ipwnzphp Posted January 3, 2011 Share Posted January 3, 2011 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++; } ?> Quote Link to comment Share on other sites More sharing options...
MMDE Posted January 3, 2011 Share Posted January 3, 2011 $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? Quote Link to comment Share on other sites More sharing options...
ipwnzphp Posted January 3, 2011 Author Share Posted January 3, 2011 i posted all the code i had! Quote Link to comment Share on other sites More sharing options...
ipwnzphp Posted January 3, 2011 Author Share Posted January 3, 2011 How i need this code to work is like this If table 1 show data form mysql for table 1, if table 2 show data for table 2. but the thing is that the data for mysql 2 comes form mysql 1. and so on for 5 times Quote Link to comment Share on other sites More sharing options...
MMDE Posted January 3, 2011 Share Posted January 3, 2011 $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 Quote Link to comment Share on other sites More sharing options...
ipwnzphp Posted January 3, 2011 Author Share Posted January 3, 2011 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.. Quote Link to comment Share on other sites More sharing options...
ipwnzphp Posted January 3, 2011 Author Share Posted January 3, 2011 $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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.