Jump to content

While loop issue


Go to solution Solved by Ch0cu3r,

Recommended Posts

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>
Link to comment
https://forums.phpfreaks.com/topic/297302-while-loop-issue/
Share on other sites

  • Solution

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
?>
Link to comment
https://forums.phpfreaks.com/topic/297302-while-loop-issue/#findComment-1516394
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.