Jump to content

While Loop w/ Mysql Querys. HELP!


ipwnzphp

Recommended Posts

I have a while loop that is making a table 5 times for me. The issue that i am having is i need to run 5 different mysql query's for the 5 different tables that the loop is making for me. How would i go about doing this?

 

Here is my code

 

<?

$i=1;

while ( $i <= 5 ) {

?>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="414" height="35" colspan="5"><strong>Level <?=$i?></strong></td>
  </tr>
  <tr>
    <td height="25"><div align="center">Join Date</div></td>
    <td><div align="center">Member Name</div></td>
    <td><div align="center">Username</div></td>
    <td><div align="center">Free/Pro</div></td>
    <td><div align="center"></div></td>
  </tr>
  
  <? 
   
  $level_one = mysql_query("select * from users where ref_by = '$username'");
  while ($level_one_do = mysql_fetch_array($level_one)) {
  
  $status = $level_one_do['status'];
  
  if($status == 1) {
  $status_type = "Free";
  } else {
  $status_type = "Pro";
  }
  ?>
  
  <tr>
    <td height="35"><div align="center"></div></td>
    <td height="35"><div align="center"></div></td>
    <td height="35"><div align="center">
      <?=$level_one_do['Username']?>
    </div></td>
    <td height="35"><div align="center"></div></td>
    <td height="35"><div align="center"><img src="images/email_forward-32.png" width="25" height="25"></div></td>
  </tr> <? } ?>
</table>
<? $i++;  } ?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/223276-while-loop-w-mysql-querys-help/
Share on other sites

$query='SELECT * FROM tablename WHERE field=\'value\'';

$result=mysql_query($query) or die(mysql_error());

if(mysql_num_rows($result)>0){

  while($row=mysql_fetch_assoc($result)){

    $table[]=$row;

  }

}

print_r($table);

 

maybe explain a bit better?

$query='SELECT * FROM table1 LEFT JOIN table2 ON table1.somefield=table2.somefield WHERE table1.somefield=\'value\' ';

$result=mysql_query($query) or die(mysql_error());

if(mysql_num_rows($result)>0){

  while($row=mysql_fetch_assoc($result)){

    $table[]=$row;

  }

}

print_r($table);

 

would this be what you want? =o

the somefield doesn't need to have the same fieldname in both tables

Let me be more clear..

 

LEVEL 1
$level_one = mysql_query("select * from users where ref_by = '$username'");
while ($level_one_do = mysql_fetch_array($level_one)) {
$level_one_do['Username'];

LEVEL 2
$level_one = mysql_query("select * from users where username = '$level_one_do[username]'");
while ($level_one_do = mysql_fetch_array($level_one)) {
$level_one_do['Username'];
}
}

 

Just some rough code..

 

$query='SELECT * FROM table1 LEFT JOIN table2 ON table1.somefield=table2.somefield WHERE table1.somefield=\'value\' ';

$result=mysql_query($query) or die(mysql_error());

if(mysql_num_rows($result)>0){

  while($row=mysql_fetch_assoc($result)){

    $table[]=$row;

  }

}

print_r($table);

 

would this be what you want? =o

the somefield doesn't need to have the same fieldname in both tables

 

Still dont understand how to sort it out though into tables of level 1, level 2 and so on until level 5.

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.