I click on a link that calls the attached function (at bottome of this message) The function works perfectly, but i need to alter it.
the second query that queries the ANSWER, I need to have it look into the answer table, return all the records where TEXT = 'No' and then of those records give me only the ones where the Q_ID column = 'Q_67'.
when i run the qry basically the entire table is returned, when only three records should be returned. What am I doing wrong?
I have echo out both sql
The request table query is: SELECT * FROM REQUEST WHERE R_STATUS = 'C' ORDER BY R_NUMBER DESC
the Answer table query is: SELECT * FROM ANSWER WHERE (Q_ID='Q_67' and TEXT='No') and R_NUMBER IN ('NA0040','NA0031','NA0030','NA0029','NA0028')
here's the function:
function getArchivedRequests($RF='',$AF='')
{
global $db;
$RL=array();
$sql = "SELECT ";
if (is_array($RF))
{
$sql .= implode(",",$RF);
} else
{
$sql .= "*";
}
$sql .= " FROM REQUEST WHERE R_STATUS = 'C' ORDER BY R_NUMBER DESC";
echo "<br>The request table query is: ".$sql."<br><br>";
$result = mysql_query($sql,$db) or die($sql);
while ($row = mysql_fetch_assoc($result))
{
foreach ($row as $key=>$val)
{
$R[$row['R_NUMBER']][$key]=$val;
}
array_push($RL,"'".$row['R_NUMBER']."'");
}
//Now get the answers
if (!empty($RL))
{
$sql = "SELECT * FROM ANSWER WHERE (Q_ID='Q_67' and `TEXT`='No') and R_NUMBER IN (".implode(",",$RL).") ";
//Quote the QIDs
if (is_array($AF))
{
foreach ($AF as $key=>$val)
{
$AF[$key]="'".$val."'";
}
$sql .= " AND Q_ID IN (".implode($AF).")";
}
echo "the Answer table query is: ".$sql."<br><br>";
$result = mysql_query($sql,$db) or die($sql);
while ($row = mysql_fetch_assoc($result))
{
$R[$row['R_NUMBER']]['ANSWER'][$row['Q_ID']]=$row['TEXT'];
}
}
return $R;
}