SirChick Posted January 11, 2008 Share Posted January 11, 2008 Im trying to filter out content into tables using if statements only the data is not coming out in the order intended! The idea in simple terms is : Code: $GetAppeals = mysql_query("SELECT * FROM reportedusers WHERE FrozenBy != 0") Or die(mysql_error()); While(row = mysql_fetch assoc($GetAppeals)){ //query1 If query1 has no rows related to a field from the main while-row { <tr><td> echo the infomation in the top group of rows</td></tr> } Else { //query2 if query2 has no rows related to a field from the main while-row{ <tr> <td echo the infomation in the middle group of rows</td></tr> }else{ <tr><td echo the information in the bottom group of rows</td></tr> } } The idea is depending weather the row is also found in a different query will depend what row it is echo'd in. In even simpler terms.. if the row is not found in "query1" it goes to top of the list in the table.. then if it is in that query then it goes to query2 and if its not in query2 it goes "below" all the rows that were not found in query1 ... you see where im going with this pattern ? Any way what is happening is they are just coming out in the order that the first query produces.. rather than placed in a certain row location...which the 2 sets of if statements are suppose to filter the data through to deal with. Hope that makes some sense! Quote Link to comment Share on other sites More sharing options...
SirChick Posted January 12, 2008 Author Share Posted January 12, 2008 bump Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 That code doesn't make sense to me. If query1 has no rows related to a field from the main while-row { ??? If there are no rows available, the while loop wouldn't run. Quote Link to comment Share on other sites More sharing options...
SirChick Posted January 12, 2008 Author Share Posted January 12, 2008 Ok ill just show you the script i got so you can follow it Its a bit long so ill take out the pointless fields that are only there for echo's. <?php $GetAppeals = mysql_query("SELECT * FROM reportedusers WHERE FrozenBy != 0") Or die(mysql_error()); while($row = mysql_fetch_array($GetAppeals)) { $RecordID = $row['RecordID']; $GetNoReplies = mysql_query("SELECT SaidBy FROM reportsituation WHERE RecordID='$RecordID' ORDER BY SaidTime DESC") Or die(mysql_error()); If(mysql_num_rows($GetNoReplies) < 1){ ?> < tr> <td width="100" align="center"><?=$RecordID?></td> </tr> <?php }Else{ $RepliesRow = mysql_fetch_assoc($GetNoReplies); $SaidBy = $RepliesRow['SaidBy']; //check if this user is staff $StaffCheck = mysql_query("SELECT UserID FROM staff WHERE UserID='$SaidBy'") Or die(mysql_error()); If(mysql_num_rows($StaffCheck) < 1){ ?> <tr> <td width="100" align="center"><?=$RecordID?></td> </tr> <?php }Else{ ?> <tr> <td width="100" align="center"><?=$RecordID?></td> </tr> <?php } ?> Now what happens is if they match in a certain area of the script then they will be above the records that were echo'd further down the script.. and under the records echo'd above it in the first validation check, you get me ? The easier method is to create one query which sorts it all firstly, how ever i tried it and asked for help here like 3 times and no one replied so i have had to it this way. 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.