php - 使用此代码我只能得到一个结果

标签 php mysql row

<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/

相关文章:

php - 计算每个变量在表中出现的次数

PHP:连接长字符串时丢失字符

php - 如何检查全局 PHP.INI 或我的 PHP 脚本中是否启用了 ini_set()?

mysql 在我杀死进程后停止并且磁盘已满 100%

MYSQL 代码在显示上创建重复行

iphone - RowAnimation 对于不同高度的单元格看起来很奇怪

javascript - 通过 POST 将 javascript 数组传递给 PHP 不起作用

PHP fgetcsv() 分隔符 ';' 无法识别

c - 你如何交换矩阵中的两行(在 C 中)?

php - 将行添加到 mysql - 随机排序 - 希望它们在顶部