Jump to content

Please help with query


SirChick

Recommended Posts

I have a query which i have got working but not quite working with what it is suppose to do.....

 

The idea is to create a list in order of "SaidBy" (which is a type of either "User" or "Staff") when these 2 groups are separated (Users being first) each group is sorted in ASC order.

 

How ever i need to make a third group for where the "SaidBy" is blank (in other words.. no one has posted anything yet).

 

So the order of the list when the query is working would show:

 

Awaiting Replies

Awaiting Replies

Awaiting Replies

Last Response: User 4 Days ago

Last Response: User 2 Days ago

Last Response: User 1 Days ago

Last Response: Staff 10 Days ago

Last Response: Staff 3 Days ago

Last Response: Staff 1 Day ago

 

 

The query won't load the "Awaiting Replies" reports (basically where there is no row related to the report in the reportsituation table which stores all the messages..

 

My Query:

 

<?php
$GetAppeals = mysql_query("select s.StaffType
     , r.SaidBy
     , r.SaidTime
 , r.RecordID
  from reportsituation as r
inner
  join Staff as s
    on s.UserID = r.SaidBy
order
    by s.StaffType desc
     , r.SaidTime  desc")
or die(mysql_error()); 
?>

 

 

Hope you can help me get this working.

Link to comment
Share on other sites

I tried to see if this would work but it does not:

 

$GetAppeals = mysql_query("select s.StaffType
     , r.SaidBy
     , r.SaidTime
 , r.RecordID
  from reportsituation as r
inner
  join Staff as s
    on s.UserID = r.SaidBy
order
    by r.SaidBy = '' desc
 , s.StaffType desc
     , r.SaidTime  desc")
or die(mysql_error()); 

Link to comment
Share on other sites

It looks as though you will need to add another table to the query

 

LEFT JOIN messages ON reportsituation.reportID = messages.reportID.

 

(I can only guess at table and column names)

 

Then the "No replies" are those where messages.reportID value IS NULL

 

 

I see what you mean... however the message table is "report situation". So would i have to load the same table twice?

Link to comment
Share on other sites

Well the tables are like this:

 

ReportedSituation:

RecordID |  SaidBy  |  SaidTime  | Text  |

 

Staff table:

UserID  |  Staff Type |

 

 

The "RecordID" is carrying the unique number of the report which is stored on a table here:

 

reportedusers:

ReportedPlayer  |  RecordID  |  Infomation  | Reported By |

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.