Simple Solution
You need to get multiple userId
s from eventmember
table which have multiple users against each event. But you are fetching only once from that query with $row = mysql_fetch_array($resultset);
, So you should get only one user, what you are getting now. Hence, the problem is, you actually have put the while
loop in a wrong place. The loop should be set like this :
$sql="SELECT userId FROM eventmember WHERE eventid='$event_id';";
$resultset = mysql_query($sql);
$num_row = mysql_num_rows($resultset);
if($num_row) {
while($row = mysql_fetch_array($resultset)) {
$sql22 = "SELECT userId, firstName FROM userinfo WHERE userId='{$row['userId']}';";
$resultset22 = mysql_query($sql22);
$row22 = mysql_fetch_array($resultset22);
$us_id = $row22['userId'];
$us_name = $row22['firstName'];
echo "<tr>";
echo "<td>ID:</td> <td class='text2' align='center' colspan='2'>
<b> $us_id </b>
</u></td>";
echo "</tr>";
//You shouldn't use a break here. This will again give you single result only.
}
}
A Better Solution
Instead of using multiple queries to get the data from userinfo
table, use JOIN to get all data with one query. Like this :
$sql="SELECT u.userId,u.firstName FROM eventmember e JOIN userinfo u ON u.userId = e.userId WHERE e.eventid='$event_id';";
$resultset = mysql_query($sql);
$num_row = mysql_num_rows($resultset);
if($num_row) {
while($row = mysql_fetch_array($resultset)) {
$us_id = $row['userId'];
$us_name = $row['firstName'];
echo "<tr>";
echo "<td>ID:</td> <td class='text2' align='center' colspan='2'>
<b> $us_id </b>
</u></td>";
echo "</tr>";
}
}
The Best and Most Secure Solution
As you should have already known mysql_*
functions are removed in PHP 7 and this functions are highly harmful for your security. So, you should either move to PDO or mysqli_* functions. I am giving here an example with mysqli_*
functions and additionally I am fetching all rows at once instead of doing fetch for each row, which is better for performance.
//First setup your connection by this way.
$link = mysqli_connect(localhost, "my_user", "my_password", "my_db");
//Now you can use mysqli
$sql="SELECT u.userId,u.firstName FROM eventmember e JOIN userinfo u ON u.userId = e.userId WHERE e.eventid=?;";
$stmt = mysqli_prepare($link, $sql);
$stmt->bind_param('s', $event_id);
$stmt->execute();
$resultset = $stmt->get_result();
$resultArray = $resultset->fetch_all();
$num_row = count($resultArray);
if($num_row) {
foreach($resultArray as $row) {
$us_id = $row['userId'];
$us_name = $row['firstName'];
echo "<tr>";
echo "<td>ID:</td> <td class='text2' align='center' colspan='2'>
<b> $us_id </b>
</u></td>";
echo "</tr>";
}
}