我有两张table。它们通过一对多(userinfo)外键关系连接。下面我要做的是回显具有给定$usrid的所有行。这可能不止一个。
不幸的是,它只回显其中一行的内容。如何将其更改为回显某个用户标识所在的所有行?
<!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>
3条答案
按热度按时间r7xajy2e1#
可以使用while循环打印所有行
4uqofj5v2#
如果有php echo语句,您可以用以下内容替换它。。。
你应该看看join来简化这一切。https://www.w3schools.com/sql/sql_join.asp
这是一个非常好/易于理解的php循环用法。https://www.tutorialspoint.com/php/php_loop_types.htm
xam8gpfp3#