我想将phpmyadmin中的数据添加为表格式,但是此代码缺少表的第一行,我不明白为什么,我在SO上尝试了其他示例,例如
for ($i=0; $i< count($num); $i++)
但这也不起作用。
有人可以看到问题吗?
谢谢
<?php
include('connect.php');
$con=mysqli_connect("localhost","******","*******","********");
$display = mysqli_query($con,"SELECT * FROM markers");
$num = mysqli_num_rows ($display);
$col = mysqli_num_fields ($display);
$row = mysqli_fetch_assoc($display);
$name = $row['name'];
?>
<?php
// start for loop
for ($i=0; $i<$num; $i++){
$row = mysqli_fetch_row($display); // fetching data
//echo results to table
echo "<tr data-name='$row[1]' data-address='$row[2]' data-lat='$row[3]' data-long='$row[4]'>";
for ($j=0; $j <$col; $j++){ // looping through each row of table
$test = $row [$j];
echo "<td test='$test'>" . $row [$j] . "</td>";
}
echo "</tr>";
}
mysqli_close($conn); // closing the connection
?>
答案 0 :(得分:1)
为什么要这样呢? 我会做一个获取数组并循环。
$result = mysqli_query($con,"SELECT * FROM markers");
while($row = mysqli_fetch_array($result))
{
echo "<tr data-name='$row['dataName']' data-address='$row['Address']' data-lat='$row['LAT']' data-long='$row['LONG']'>"
}
这将循环直到您没有更多行为止。