Jump to content

While loop issue


CloudBreaker

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.