CloudBreaker Posted July 15, 2015 Share Posted July 15, 2015 Not sure what I'm missing here. I have a select statement which joins tables. I have three projects associated with the user name, however the last project associated with the user is the only one showing up. It's late, and maybe I'm just not seeing it. If I run the identical select statement in phpAdmin, I get the correct result. Is there something wrong with my "While loop"? Thanks, CB <?php //Getting projects from user session variable $userid=$_SESSION['id']; $sql = "SELECT projects.name,projects.project_id\n" . "FROM hsa_users,projects,member_project\n" . "WHERE projects.id=member_project.project_id\n" . "AND member_project.user_id=$userid\n" . "AND hsa_users.id=$userid"; $result=mysqli_query($conn,$sql); $row=mysqli_fetch_assoc($result); $run = mysqli_query($conn, $sql); $i=0; while($row=mysqli_fetch_assoc($run)){ $projName =$row['name']; $projNumber = $row["project_id"]; $i++; } ?> <tr align="center"> <td><?php echo $projName;?></td> <td><?php echo $projNumber;?></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/297302-while-loop-issue/ Share on other sites More sharing options...
Solution Ch0cu3r Posted July 15, 2015 Solution Share Posted July 15, 2015 You need to output the table row within the while loop while($row=mysqli_fetch_assoc($run)) { $projName =$row['name']; $projNumber = $row["project_id"]; $i++; ?> <tr align="center"> <td><?php echo $projName;?></td> <td><?php echo $projNumber;?></td> </tr> <?php } // end while loop ?> Quote Link to comment https://forums.phpfreaks.com/topic/297302-while-loop-issue/#findComment-1516394 Share on other sites More sharing options...
CloudBreaker Posted July 15, 2015 Author Share Posted July 15, 2015 Thanks Ch0cu3r. Quote Link to comment https://forums.phpfreaks.com/topic/297302-while-loop-issue/#findComment-1516409 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.