我正在尝试显示基于mysql输出的链接列表。代码工作,但它删除了第一条记录。我知道这是因为重复[#row3 = mysql_fetch_array($ result3)]条目,但如果我删除一个代码失败。有人可以建议修复吗?
由于
<?php
$sql3 = "SELECT `Record_ID`, `Name` FROM `rides` WHERE `Rating` = 3";
$result3=mysql_query($sql3)or die(mysql_error());
//var_dump ($result3);
$num = mysql_num_rows($result3);
while ($row3 = mysql_fetch_array($result3))
{
echo "<table>";
for ($i = 0; $i < $num; $i++){
$row3 = mysql_fetch_array($result3);
//var_dump($row3);
$ridesid = $row3[0];
$rides = $row3[1];
echo "<tr>";
echo "<a href='attraction_page.php?rideID=". urlencode($ridesid) ."'>$rides</a>";
echo "<br />";
echo "</tr>";
}
echo '</table>';
}
?>
答案 0 :(得分:1)
你两次拿同样的东西!
试试这个:
<?php
$sql3 = "SELECT `Record_ID`, `Name` FROM `rides` WHERE `Rating` = 3";
$result3=mysql_query($sql3)or die(mysql_error());
//var_dump ($result3);
$num = mysql_num_rows($result3);
echo "<table>";
while ($row3 = mysql_fetch_array($result3))
{
$ridesid = $row3[0];
$rides = $row3[1];
echo "<tr>";
echo "<a href='attraction_page.php?rideID=". urlencode($ridesid) ."'>$rides</a>";
echo "<br />";
echo "</tr>";
}
echo '</table>';
?>
答案 1 :(得分:0)
只调用一次mysql_fetch_array()...