Can someone help me with this query ? am i going about it all wrong ?
what i want to do is conduct a search using drop down menus. two of them in this case.
you make a selection based on what field and agency_name is selected.
in this case i have a set level='Graduate', and then i want the search to be conducted based on whether any or all or just one of the selections have been made. the way it is right now - only when both selections have been made does it work. please help, thanks.
<?php
$db = @pg_connect("","","","","funds");
if (!$db) {echo "Could not connect to the Funding database"; exit;}
$query = "Select * from scholarship where level='Graduate'";
if (!empty($field)|!empty ($agency_name))
{
$query .=" AND field='$field' AND agency_name='$agency_name'";
}
elseif (!empty($field))
{
$query .=" AND field='$field'";
}
elseif (!empty($agency_name))
{
$query .=" AND agency_name='$agency_name'";
}
$result = @pg_exec($db, $query);
if (!$result) {echo"<b>Sorry, an error occurred while processing your query.</b>"; exit;}
$color1 = "#EEEEF8";
$color2 = "#ffffff";
$numrows = @pg_numrows($result);
if (!$numrows) {echo"<b>No results matched your query, try another set of selections.</b>"; exit;}
$row=0;
$row_num=1;
do
{
$color = ($row_num%2) ? $color2 : $color1;
$myrow = @pg_fetch_row ($result,$row);
if (!$myrow) {echo"<b>No results matched your query, try another set of selections.</b>"; exit;}
print ("<tr><td width=\"10\" bgcolor=".$color." valign=\"top\">
<FONT COLOR=\"#003399\">$row_num</font></td>
<td bgcolor=".$color." width=\"400\" valign=\"top\">
<a href=\"scholview.php?schol_id=".$myrow[0]."\">$myrow[1]</a></td>
<td bgcolor=".$color." width=\"120\" valign=\"top\">$myrow[2]</td >
<td bgcolor=".$color." width=\"175\" valign=\"top\">$myrow[3]</td >
</tr>\n");
$row++;
$row_num++;}
while ($row < $numrows);
print ("</table><br>\n");
pg_close($db);
?>