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

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.