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

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

$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.

Link to comment
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.