I have an MYSQL query I need to only display Open Cases the open status is in another table so I need to link History.sid to Client.ref
The table looks like Client which has fields ref and statusRB which statusRB shows Open and Closed and then History which has sid which is same id number as ref
So i need to find a way a lining sid to ref before it displays the results of only Open cases
$query = mysql_query("select FROM_UNIXTIME(a.maxepoch,\"%d-%m-%Y\"), b.id, b.sid, b.did, b.type, b.nextaction, FROM_UNIXTIME(b.nextactiondate,\"%d-%m-%Y\") from History b,
(select max(epoch) as maxepoch from History
group by did) a
#where a.maxepoch = b.epoch and b.epoch < (unix_timestamp(now()) - 2592000)
Where a.maxepoch = b.epoch and b.epoch < (unix_timestamp(now()) - 604800)
order by b.epoch desc");
$mydate = date("d-m-Y");
$message = "<br><br><h1>30 day Report for $mydate</h1><br>";
$message .= "<table border=\"1\"><tr><strong><td>Customer Ref</td><td>Client Ref</td><td>Action</td><td>Action Date</td><td>Next Action</td><td>Next Action Date</td></strong></tr>";
while ($def = mysql_fetch_row($query)) {
$sid = $def[2];
$did = $def[3];
$type = $def[4];
$nextaction = $def[5];
$nextactiondate = $def[6];
$maxepoch = $def[0];