Jump to content

[SOLVED] query for array? help me


nrsh_ram

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/143505-solved-query-for-array-help-me/
Share on other sites

* 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;
         ?>   
                  
         
         
         
      

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.