query for array? help me

  • nrsh_ram
  • Novice
  • Novice
  • nrsh_ram
  • Posts: 30
  • Loc: malaysia

Post 3+ Months Ago

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?

Code: [ Select ]
 
$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"];
 
}
 
  1.  
  2. $cur_login = $_SESSION["username"];
  3. $conn= db_connect();
  4. $aa=0;  
  5.  
  6. $query = "select  mentee, username_mentee from mentormentee where username_mentor = '$cur_login'";
  7. $result = $conn->query($query);
  8.  
  9. if($result->num_rows >0){
  10.  $row = mysqli_fetch_assoc($result);
  11.  
  12. $m_mentee= $row["mentee"];
  13. $m_username= $row["username_mentee"];
  14.  
  15. }
  16.  



the table
Code: [ Select ]
 
<table width="567" border="0" align="center">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</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; ?>&nbsp;</td>
        <td><?php echo $m_mentee; ?>&nbsp;</td>
        <td><?php echo $m_username; ?>&nbsp;</td>
        <td>&nbsp;</td>
      </tr><?php } ?>
    </table>
 
 
  1.  
  2. <table width="567" border="0" align="center">
  3.       <tr>
  4.         <td>&nbsp;</td>
  5.         <td>&nbsp;</td>
  6.         <td>&nbsp;</td>
  7.         <td>&nbsp;</td>
  8.       </tr>
  9.       <tr>
  10.         <td width="109" bgcolor="#FFD9D9"><div align="center">No</div></td>
  11.         <td width="111" bgcolor="#FFD9D9">Name</td>
  12.         <td bgcolor="#FFD9D9" width="149"><div align="center">Id</div></td>
  13.         <td bgcolor="#FFD9D9" width="182"><div align="center">Major</div></td>
  14.       </tr>
  15.       <tr>
  16.      <?php
  17.          while ($row = mysqli_fetch_assoc($result)){
  18.          $aa = $aa + 1;
  19.          ?>  
  20.                  <td><?php echo $aa; ?>&nbsp;</td>
  21.         <td><?php echo $m_mentee; ?>&nbsp;</td>
  22.         <td><?php echo $m_username; ?>&nbsp;</td>
  23.         <td>&nbsp;</td>
  24.       </tr><?php } ?>
  25.     </table>
  26.  
  27.  
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8415
  • Loc: USA

Post 3+ Months Ago

PHP Code: [ Select ]
<?php
$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){
while($row = mysqli_fetch_assoc($result))
{
 
   $m_mentee= $row["mentee"];
   $m_username= $row["username_mentee"];
?>
 <table width="567" border="0" align="center">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</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
      $aa = $aa + 1;
      ?>
            <td><?php echo $aa; ?>&nbsp;</td>
      <td><?php echo $m_mentee; ?>&nbsp;</td>
      <td><?php echo $m_username; ?>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
   </table>
<?php
}
 
}
?>
  1. <?php
  2. $cur_login = $_SESSION["username"];
  3. $conn= db_connect();
  4. $aa=0;
  5.  
  6. $query = "select mentee, username_mentee from mentormentee where username_mentor = '$cur_login'";
  7. $result = $conn->query($query);
  8.  
  9. if($result->num_rows >0){
  10. while($row = mysqli_fetch_assoc($result))
  11. {
  12.  
  13.    $m_mentee= $row["mentee"];
  14.    $m_username= $row["username_mentee"];
  15. ?>
  16.  <table width="567" border="0" align="center">
  17.     <tr>
  18.       <td>&nbsp;</td>
  19.       <td>&nbsp;</td>
  20.       <td>&nbsp;</td>
  21.       <td>&nbsp;</td>
  22.     </tr>
  23.     <tr>
  24.       <td width="109" bgcolor="#FFD9D9"><div align="center">No</div></td>
  25.       <td width="111" bgcolor="#FFD9D9">Name</td>
  26.       <td bgcolor="#FFD9D9" width="149"><div align="center">Id</div></td>
  27.       <td bgcolor="#FFD9D9" width="182"><div align="center">Major</div></td>
  28.     </tr>
  29.     <tr>
  30.    <?php
  31.       $aa = $aa + 1;
  32.       ?>
  33.             <td><?php echo $aa; ?>&nbsp;</td>
  34.       <td><?php echo $m_mentee; ?>&nbsp;</td>
  35.       <td><?php echo $m_username; ?>&nbsp;</td>
  36.       <td>&nbsp;</td>
  37.     </tr>
  38.    </table>
  39. <?php
  40. }
  41.  
  42. }
  43. ?>
  • nrsh_ram
  • Novice
  • Novice
  • nrsh_ram
  • Posts: 30
  • Loc: malaysia

Post 3+ Months Ago

its working..thank you
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8415
  • Loc: USA

Post 3+ Months Ago

Yeah... you just got to know where to put the actual loops.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 105 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.