【发布时间】:2018-06-23 19:13:58
【问题描述】:
我有两张桌子。它们通过一个(用户信息)到多个(成就)外键关系连接。我在下面尝试做的是回显所有具有给定 $usrid 的行。这可能不止一个。
不幸的是,它只回显其中一行的内容。如何更改它以回显存在某个用户 ID 的所有行?
<!DOCTYPE HTML>
<head>
<?php $usrid = $_GET['usrid'];
$connection = @mysqli_connect("localhost","root","","Rain")
OR die('Could not connect' .
mysqli_connect_error());
$query = "SELECT usrid, username, oldname, languages, joindate, art, hunting, frontwebdev, backwebdev, writing, programming, se, smm, pentesting, timezone, availability, reliability, profilePicture FROM userinfo WHERE usrid='" . $usrid . "';";
$response = @mysqli_query($connection,$query);
$row = @mysqli_fetch_array($response);
$username = $row['username'];
$achvquery = "SELECT achieveid, usrid, achievementname, achievementdescr, timestamp FROM achievements WHERE usrid=" . $usrid . ";";
$achvresponse = @mysqli_query($connection,$achvquery);
$achvrow = @mysqli_fetch_array($achvresponse);
$achvtitle = $achvrow['achievementname'];
$achvdescr = $achvrow['achievementdescr'];
?>
<title>
All Achievements
</title>
</head>
<body>
<span> <?php echo "<span> " . $username . "s OD Achievement History "; ?> </span>
<span id="newAchvLink"> <?php echo "<a id='addNewLink' href='addachievement.php?usrid=" . $usrid . "'> Add new</a>"; ?></span>
<br /> <?php echo "<h2> Achv: </h2> <h3 class='achvtitle'>" . $achvtitle . "</h3>"; echo $achvdescr;?><br /><br />
</body>
</html>
【问题讨论】:
-
您需要不断地获取行,使用
while块stackoverflow.com/questions/12647154/… -
使用while循环显示所有行
-
我不确定在这种情况下如何使用它@Ghost
-
另外,不要使用@ 运算符来防止错误消息。此外,您的代码容易受到 SQL 注入的攻击。
-
@dowo3 为什么要重新检查你的代码来重构它?立即修复它,以便您在推出软件时节省时间