<a href="add.php">add new product</a><br>
<br>
<?php
include("mysql.php");
$result = mysql_query("SELECT * FROM gallery ");
$just = mysql_fetch_array($result);
$num=mysql_num_rows($result);
$table="";
$table.="<td>delete</td>";
$table.="<td>update</td>";
if ($num > 0 ) {
$i=0;
while($just = mysql_fetch_array($result))
{
$num=mysql_num_rows($result);
{
$table .= "<tr>";
$table .= "<td><a href=\"delete.php?name=".$just['name']."&id=".$just['id']."\">".$just['title']."</a></td>";
$table .= "<td><a href=\"update.php?description=".$just['description']."&title=".$just['title']."&id=".$just['id']."\">".$just['title']."</a></td>";
}
$table .= "</tr>";
while ($i < $num) {
$name = stripslashes(mysql_result($result,$i,"name"));
$title = stripslashes(mysql_result($result,$i,"title"));
$description = stripslashes(mysql_result($result,$i,"description"));
++$i; }
}
}
else { $table = '<tr><td colspan="2" align="center">Nothing found</td></tr>'; }
?>
<table border="1" cellpadding="1" cellspacing="2"><? echo $table ?></table>
早上好,在上面的代码中,我试图创建一个包含 2 列删除和更新的表,能够通过此页面管理 mysql,但是我只从 mysql 表中得到 1 行,尽管我期望有 4 行(保存了 4 行在 mysql 表中) 这里有什么问题,提前致谢
最佳答案
<a href="add.php">add new product</a><br>
<br>
<?php
include("mysql.php");
$result = mysql_query("SELECT * FROM `gallery`");
$num = mysql_num_rows($result);
$table = "";
$table .= "<td>delete</td>";
$table.="<td>update</td>";
if ($num > 0 ) {
$i=0;
while($just = mysql_fetch_assoc($result)) {
$num=mysql_num_rows($result);
$table .= "<tr>";
$table .= "<td><a href=\"delete.php?name=".$just['name']."&id=".$just['id']."\">".$just['title']."</a></td>";
$table .= "<td><a href=\"update.php?description=".$just['description']."&title=".$just['title']."&id=".$just['id']."\">".$just['title']."</a></td>";
}
$table .= "</tr>";
while ($i < $num) {
$name = stripslashes(mysql_result($result,$i,"name"));
$title = stripslashes(mysql_result($result,$i,"title"));
$description = stripslashes(mysql_result($result,$i,"description"));
++$i;
}
} else {
$table = '<tr><td colspan="2" align="center">Nothing found</td></tr>';
}
?>
<table border="1" cellpadding="1" cellspacing="2"><? echo $table ?></table>
关于php - 使用此代码我只能得到一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10360610/