Jump to content

order table rows using if statements


SirChick

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/85611-order-table-rows-using-if-statements/
Share on other sites

Ok ill just show you the script i got so you can follow it  :P

 

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.

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.