Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从mysql检索数据并使用php将其显示在表中_Php_Mysql - Fatal编程技术网

从mysql检索数据并使用php将其显示在表中

从mysql检索数据并使用php将其显示在表中,php,mysql,Php,Mysql,我试图从数据库中检索所有数据并将其显示在表中。但我做不到,我面临一些问题。我得到的错误是 此页面不工作 localhost当前无法处理此请求 这是我的密码 <html> <body> <table style="width:100%"> <tr> <th>Driverid</th> <th>Truckid</th> <th>Imagecount</th&

我试图从数据库中检索所有数据并将其显示在表中。但我做不到,我面临一些问题。我得到的错误是

此页面不工作


localhost当前无法处理此请求

这是我的密码

<html>
<body>
<table style="width:100%">
  <tr>
    <th>Driverid</th>
    <th>Truckid</th> 
    <th>Imagecount</th>
    <th>Trainingstatus</th>
  </tr>
<?php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "IDdb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT DriverID, TruckID, Imagecount, Trainingstatus FROM IDs";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    $driverid = $row["Driverid"];
    $truckid = $row["Truckid"];
    $imagecount = $row["Imagecount"];
    $trainingstatus = $row["Trainingstatus"];?>
<tr>
    <td><?php echo $driverid; ?></td>
    <td><?php echo $truckid; ?></td>
    <td><?php echo $imagecount; ?></td>
    <td><?php echo $trainingstatus; ?></td>
  </tr>
</table>
    <?php}
} else {
    echo "0 results";
}
$conn->close();
?>
</body>

</html>

胡闹
卡车司机
图像计数
训练状态

请更换您的代码


请替换您的代码


请阅读上关于如何在php中定义变量的部分,然后检查代码中定义的变量。

请阅读上关于如何在php中定义变量的部分,然后检查代码中定义的变量。

您没有启动表标记,也没有在循环中,主要部分是sdd空间


您尚未启动表标签,也未进入循环,主要部分是sdd空间



localhost当前无法处理此请求。此错误不适用于您的程序其他页面正常工作?是其他页面正常工作。不是网络问题检查我的答案我认为应该是worklocalhost当前无法处理此请求。此错误不适用于您的程序其他页面正常工作?是的其他页面正常工作。这不是网络问题检查我的答案我认为它应该正常工作我很抱歉这是我这边的错误。我给错了。我已将driverid更改为$driverid,但它不正常我很抱歉这是我这边的错误。我给错了。我给错了将driverid更改为$driverid,尽管它不起作用。我错误地提到了它,变量不是问题。我已将driverid更改为$driverid,尽管它不起作用。
中的大括号我错误地提到了它,变量不是问题。我已从driverid更改为$driverid,尽管它不工作
中的大括号不工作。我认为问题在于循环,如果我打印一个数据,它工作正常。你检查过这段代码吗?因为我已经测试了它只是调试循环,我认为你没有问题,它不工作。我认为问题在于循环,如果我打印一个数据,它工作得很好。你检查过这个代码吗?因为我已经对它进行了测试,所以我认为您对调试循环有问题
driverid = $row["Driverid"];
truckid = $row["Truckid"];
imagecount = $row["Imagecount"];
trainingstatus = $row["Trainingstatus"];
$driverid = $row["Driverid"];
$truckid = $row["Truckid"];
$imagecount = $row["Imagecount"];
$trainingstatus = $row["Trainingstatus"];
if ($result->num_rows > 0) {
echo '<table>';
    // output data of each row
    while($row = $result->fetch_assoc()) {
    $driverid = $row["Driverid"];
    $truckid = $row["Truckid"];
    $imagecount = $row["Imagecount"];
    $trainingstatus = $row["Trainingstatus"];?>
<tr>
    <td><?php echo $driverid; ?></td>
    <td><?php echo $truckid; ?></td>
    <td><?php echo $imagecount; ?></td>
    <td><?php echo $trainingstatus; ?></td>
  </tr>
    <?php }
echo '</table>';
} else {
    echo "0 results";
}