H,之前我把我的脚本搞砸了。然后我的整个剧本变得疯狂。现在,我删除了与分页相关的所有脚本,突然间,现在我无法显示所有相同ID的行。例如。对于id 99,我在sql中有9行相同的id。但它只显示5行。请帮忙谢谢。
$query="SELECT ua.* FROM useradvert ua INNER JOIN users u ON ua.id =u.id
WHERE ua.id='".$id."'";
$stmt = $conn->prepare($query);
$stmt->execute();
$res2 = $stmt->get_result();
$row2 = $res2->fetch_array();
$_SESSION['name2'] = $row2['name2'];
$_SESSION['color2'] = $row2['color2'];
$_SESSION['hobby2'] = $row2['hobby2'];
$_SESSION['radiobtn'] = $row2['radiobtn'];
$_SESSION['kupon'] = $row2['kupon'];
$_SESSION['image'] = $row2['image'];
$_SESSION['image2'] = $row2['image2'];
继续下面......同一页
while ($row2 = $res2->fetch_array(MYSQLI_ASSOC)){
echo "<li>".$_SESSION['name2'] = $row2['name2']."</li>";
echo "<li>".$_SESSION['color2'] = $row2['color2']."</li>";
echo "<li>".$_SESSION['hobby2'] = $row2['hobby2']."</li>";
echo "<li>".$_SESSION['radiobtn'] = $row2['radiobtn']."</li>";
echo "<li>".$_SESSION['kupon'] = $row2['kupon']."</li>";
echo "<li>".$_SESSION['image'] = $row2['image']."</li>";
echo "<li>".$_SESSION['image2'] = $row2['image2']."</li>";}
答案 0 :(得分:1)
你应该删除这段代码,用fetch_array()函数正确循环:
$row2 = $res2->fetch_array();
$_SESSION['name2'] = $row2['name2'];
$_SESSION['color2'] = $row2['color2'];
$_SESSION['hobby2'] = $row2['hobby2'];
$_SESSION['radiobtn'] = $row2['radiobtn'];
$_SESSION['kupon'] = $row2['kupon'];
$_SESSION['image'] = $row2['image'];
$_SESSION['image2'] = $row2['image2'];
答案 1 :(得分:0)
看起来您的SQL查询可能导致问题,请尝试删除双引号
$ query =&#34; SELECT ua。* FROM useradvert ua INNER JOIN users u ON ua.id = u.id WHERE ua.id =&#39;&#34;。$ id。&#34;&#39;&#34;;
要
$ query =&#34; SELECT ua。* FROM useradvert ua INNER JOIN users u ON ua.id = u.id WHERE ua.id =&#39;。$ id。&#39;&#34;;