Hello
I was just wondering how you do this properly
I have this code
//year - user selects all
//consultee - user selects a particular consultee
//consultant - user selects all
if ($POST['date_search'] == "All")
if ($POST['consultee_search']!= "All")
if ($_POST['consultant_search'] == "All")
//performs SQL for a particular consultee with all years and consultants
{
$result = odbc_exec($connect,
"SELECT doc_url, doc_title
FROM (documents
INNER JOIN doc_types
ON documents.doc_id=doc_types.doc_id)
INNER JOIN doc_consultees
ON documents.doc_id=doc_consultees.doc_id
WHERE doc_types.type_id=13
AND doc_consultees.consultee_id=".$_POST['consultee_search']."");
while ($row = odbc_fetch_array($result))
//returns the titles acting as hyperlinks to the documents themselves
{echo "<ul><li><a href='" . $row['doc_url'] . "'>'" . $row['doc_title'] . "'</a></li></ul>"; }
}
//year - user selects particular year
//consultee - user selects a particular consultee
//consultant - user selects all
if ($POST['date_search'] !="All")
if ($POST['consultee_search']!= "All")
if ($_POST['consultant_search']== "All")
//performs SQL for a particular consultee and a particular year with all consultants
{
$result = odbc_exec($connect, "SELECT doc_url, doc_title
FROM (documents
INNER JOIN doc_types
ON documents.doc_id=doc_types.doc_id)
INNER JOIN doc_consultees
ON documents.doc_id=doc_consultees.doc_id
WHERE doc_types.type_id=13
AND doc_consultees.consultee_id=".$POST['consultee_search']."
AND doc_date_yr = '" . $POST['date_search'] . "'");
while ($row = odbc_fetch_array($result))
//returns the titles acting as hyperlinks to the documents themselves
{
echo "<ul><li><a href='" . $row['doc_url'] . "'>'" . $row['doc_title'] . "'</a></li></ul>";
}
}
I am sorry I odn't kno whow to make it all the right colours - but if you see I have two identical SQL statements apart from the fact that the second time I write it out is has an extra AND thing on teh end of the WHERE clause
So it would be much simpler if I only had to write it out once : someting like this
SQL = "like when I write it out the first time "
then if the first set of conditions are all met
perform the SQL and display the results like I tell to
if the second set of conditions are all met do the same SQL but with that extra bit on the end
Do you see what I mean???
:-)