nrsh_ram Posted February 2, 2009 Share Posted February 2, 2009 good morning to all... im newbie to php n mysql.. i have problem...in database under "mentor1" have 2mentees "mentee1 n mentee2" so i want the system show the all mentee.. i have tried,but its only show mentee1 only, how to make it loop to show all mentee? $cur_login = $_SESSION["username"]; $conn= db_connect(); $aa=0; $query = "select mentee, username_mentee from mentormentee where username_mentor = '$cur_login'"; $result = $conn->query($query); if($result->num_rows >0){ $row = mysqli_fetch_assoc($result); $m_mentee= $row["mentee"]; $m_username= $row["username_mentee"]; } the table <table width="567" border="0" align="center"> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td width="109" bgcolor="#FFD9D9"><div align="center">No</div></td> <td width="111" bgcolor="#FFD9D9">Name</td> <td bgcolor="#FFD9D9" width="149"><div align="center">Id</div></td> <td bgcolor="#FFD9D9" width="182"><div align="center">Major</div></td> </tr> <tr> <?php while ($row = mysqli_fetch_assoc($result)){ $aa = $aa + 1; ?> <td><?php echo $aa; ?> </td> <td><?php echo $m_mentee; ?> </td> <td><?php echo $m_username; ?> </td> <td> </td> </tr><?php } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/143505-solved-query-for-array-help-me/ Share on other sites More sharing options...
Maq Posted February 2, 2009 Share Posted February 2, 2009 * Not tested * You don't need this stuff in the top PHP part: if($result->num_rows >0){ $row = mysqli_fetch_assoc($result); $m_mentee= $row["mentee"]; $m_username= $row["username_mentee"]; } and you should change this part to something like: while ($row = mysqli_fetch_assoc($result)){ $aa += 1; ?> Quote Link to comment https://forums.phpfreaks.com/topic/143505-solved-query-for-array-help-me/#findComment-752818 Share on other sites More sharing options...
nrsh_ram Posted February 2, 2009 Author Share Posted February 2, 2009 thank you..Maq, now its working. thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/143505-solved-query-for-array-help-me/#findComment-752833 Share on other sites More sharing options...
Maq Posted February 2, 2009 Share Posted February 2, 2009 Great, did you understand the modifications? Oh yeah, mark as SOLVED please... Quote Link to comment https://forums.phpfreaks.com/topic/143505-solved-query-for-array-help-me/#findComment-752839 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.