我有两张桌子。它们通过一个(userinfo)对多个(成就)外键关系进行连接。下面我尝试做的是回显具有给定$usrid的所有行。这可能不止一个。
不幸的是,它只回显其中一行的内容。如何将其更改为回显存在某个用户is的所有行?
<!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>发布于 2018-01-15 15:09:05
您可以使用while循环来打印所有行
$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);
while ($row = @mysqli_fetch_array($response))
{
echo $row['username'];
}发布于 2018-01-15 15:14:06
如果您有PHP echo语句,则可以将其替换为以下内容:
while($row = $result->fetch_assoc($response)) {
echo "<span> " . $username . "s Op Achievement History ";您应该考虑使用JOIN来为您简化所有这些操作。https://www.w3schools.com/sql/sql_join.asp
这是一个非常好理解/易于理解的PHP循环用法。https://www.tutorialspoint.com/php/php_loop_types.htm
发布于 2018-01-15 15:53:46
first table query
while loop
{
$userid=first_table_data['user_id'];
2nd table query where userid=$userid
while loop
{
}
all value save in array
}
print valuehttps://stackoverflow.com/questions/48258202
复制相似问题