我使用PHP表单将数据输入到MySQL表中,并在请求时显示该表(这必须使用MySQLi完成)。
我成功地插入了数据,但在使用MySQLi和PHP显示表时遇到了问题。我需要在XHTML表中显示结果。
我试着遵循我在网上找到的教程,但它们似乎不起作用;我当前的代码显示标题,然后在标题下显示一个空行,而不是表中的数据。
我知道它是连接的,就像我说的,它可以插入。有人能告诉我(并解释一下)我将如何解决我的问题吗?
$query = "select * from $table_name;";
if ($result = mysqli_query($db_link, $query)){
echo "<table>";
//header
echo "<tr><td>Date Added</td>";
echo "<td>Name</td>";
echo "<td>Email</td>";
echo "<td>Gender</td>";
echo "<td>Country</td>";
echo "<td>Subject</td>";
echo "<td>Comment</td>";
echo "<td>Subscription</td></tr>";
//data
while ($row = $result->fetch_row()) {
$Row = mysqli_fetch_assoc($result);
echo "<tr><td>{$Row[0]}</td>";
echo "<td>{$Row[1]}</td>";
echo "<td>{$Row[2]}</td>";
echo "<td>{$Row[3]}</td>";
echo "<td>{$Row[4]}</td>";
echo "<td>{$Row[5]}</td>";
echo "<td>{$Row[6]}</td>";
echo "<td>{$Row[7]}</td></tr>";
}
echo "</table>";
}
mysqli_free_result($result);
mysqli_close($db_link);
尝试mysqli_fetch_array()
$query = "select * from $table_name;";
if ($result = mysqli_query($db_link, $query)){
echo "<table>";
//header
echo "<tr><td>Date Added</td>";
echo "<td>Name</td>";
echo "<td>Email</td>";
echo "<td>Gender</td>";
echo "<td>Country</td>";
echo "<td>Subject</td>";
echo "<td>Comment</td>";
echo "<td>Subscription</td></tr>";
//data
while ($row = mysqli_fetch_array($result)) {
echo "<tr><td>{$row[0]}</td>";
echo "<td>{$row[1]}</td>";
echo "<td>{$row[2]}</td>";
echo "<td>{$row[3]}</td>";
echo "<td>{$row[4]}</td>";
echo "<td>{$row[5]}</td>";
echo "<td>{$row[6]}</td>";
echo "<td>{$row[7]}</td></tr>";
}
echo "</table>";
}
mysqli_free_result($result);
mysqli_close($db_link);
您必须退出php
Echo "<td>".$row[6]."</td>";
http://www.w3schools.com/php/php_mysql_select.asp
希望它能在中工作
while($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>". $row["DateAdded"]."</td>";
echo "<td>". $row["Name"]."</td>";
echo "<td>".$row["Email"] ."</td>";
echo "<td>".$row["Gender"] ."</td>";
echo "<td>".$row["Country"] ."</td>";
echo "<td>".$row["Subject"] ."</td>";
echo "<td>".$row["Comment"] ."</td>";
echo "<td>".$row["Subscription"] ."</td>";
echo "</tr>";
}