Php 将mysqli_fetch_数组中的项目回显到html表中,td标记不会显示

Php 将mysqli_fetch_数组中的项目回显到html表中,td标记不会显示,php,mysql,mysqli,echo,Php,Mysql,Mysqli,Echo,这是我的代码,我得到了要显示的项目,但是没有任何东西会在标记中回音。我试着删除php echo语句,试着写一些文本,但仍然一无所获。提前谢谢 <?php //Create a connection $connect = mysqli_connect('localhost', 'root', 'bachi619', 'company'); //check connection if(mysqli_connect_errno($connect)){ echo 'Failed

这是我的代码,我得到了要显示的项目,但是没有任何东西会在标记中回音。我试着删除php echo语句,试着写一些文本,但仍然一无所获。提前谢谢

    <?php
//Create a connection
$connect = mysqli_connect('localhost', 'root', 'bachi619', 'company');

//check connection
if(mysqli_connect_errno($connect)){
    echo 'Failed to connecto to database'.mysqli_connect_error();
}

$result= mysqli_query($connect, "SELECT * FROM employees");
?>

<br>
    <table width="500", cellpadding=5 callspacing=5 border=1>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Last Name</th>
            <th>Department</th>
            <th>Email</th>
        </tr>
    <?php while($rows = mysqli_fetch_array($result)): ?>
    <tr>
        <td><?php echo $rows['id']; ?></td>
        <td><?php echo $rows['first_name']; ?></td>
        <td><?php echo $rows['last_name']; ?></td>
        <td><?php echo $rows['department']; ?></td>
        <td><?php echo $rows['email']; ?></td>
    </tr>
    <?php endwhile; ?>



    </table>

您在几个地方缺少PHP:

<?php
$connect = mysqli_connect('localhost', 'root', '11111', 'company');
if(mysqli_connect_errno($connect)){
echo 'Failed to connecto to database'.mysqli_connect_error();}


$result= mysqli_query($connect, "SELECT * FROM employees");
?>
 <table width="500", cellpadding=5 callspacing=5 border=1>
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Last Name</th>
        <th>Department</th>
        <th>Email</th>
    </tr>
<?php while($rows = mysqli_fetch_array($result)): ?>
<tr>
    <td><?php echo $rows['id']; ?></td>
    <td><?php echo $rows['first_name']; ?></td>
    <td><?php echo $rows['last_name']; ?></td>
    <td><?php echo $rows['department']; ?></td>
    <td><?php echo $rows['email']; ?></td>
</tr>
<?php endwhile; ?>



</table>

我以前也有同样的问题。起初,我认为mysqli_fetch_数组无法在标记内部工作。但现在它终于做到了。无论如何,在检查代码后,您是否尝试删除:in 因为据我所知,你不需要;或者:如果您在while循环或任何循环函数中调用函数。 试试这个:
虽然$row=mysqli\u fetch\u assoc$result

将其放在脚本之前,看看会发生什么。ini设置“显示错误”,1;错误报告全部;在这里粘贴代码可能是个错误,但是在PHP代码的第一块周围没有任何标记在开始表声明之前丢失PHP标记抱歉,我刚刚更新了我的代码,似乎在尝试复制和粘贴代码时出错,我只是用我正在使用的无效代码更新了代码。print_$result;为了确保查询实际返回的数据是奇怪的,看起来在我将代码粘贴到原始帖子时出现了问题。我刚刚更新了它,现在它有了我正在尝试使用但不起作用的代码。两个语法错误:逗号和单词callspacing(而不是cellspacing)中的拼写错误应该读作“谢谢”,我根本没有看到。刚刚更新了,但echo的声明还是没有成功。不客气。确保表/列中确实有数据,注意字母大小写等。名字和名字是两种完全不同的动物。就我个人而言,我不会这样做@User2684521感谢我检查了表和列中是否有数据,如果我在$result声明下编写此代码,$rows=mysqli_fetch_array$result{echo$rows['first_name']..$rows['last_name'];}