Apologies on the vauge title. I have a form - http://www.outcomesforchildren.org/familysupport-form.html
The first select drop down has a list of services (named ‘services’). I’m trying to write a query that allows the option selected to throw back the results from the DB that are of that service type.
The DB has each option (service) listed as a INT field - e,g ‘Carer’ is an INT field in the DB 1 = Yes its a Carer 2 = Not this service.
I have no options on the backend and can only adjust the query I currently have to display the results which is;
<?php
$org_name=$_POST['org_name'];
$area=$_POST['area'];
//$services=$_POST['services'];
$hardiker=$_POST['hardiker'];
//organisation name feedback
if (isset ($org_name))
{
echo '<h3>Organisation Name: <span style="color: #000; font-weight:bold">'.$org_name.'</span></h3>';
}
else
{
echo '<h3>You have searched for all organisation names.</h3>';
}
/*service type feedback
if (isset ($services))
{
echo '<h3>Services: <span style="color: #000; font-weight:bold">'.$services.'</span></h3>';
}
else
{
echo '<h3 >You have searched for all services.</h3>';
}*/
//area selected feedback
if (isset ($area))
{
echo '<h3>Area: <span style="color: #000; font-weight:bold">'.$area.'</span></h3>';
}
else
{
echo '<h3>You have searched all areas.</h3>';
}
//hardiker feedback
if (isset ($hardiker))
{
echo '<h3>Hardiker: <span style="color: #000; font-weight:bold">'.$hardiker.'</span></h3>';
}
else
{
echo '<h3>You have searched all hardiker levels.</h3>';
}
echo $services;
//mysql query here
$sql_result= "SELECT * FROM family_support WHERE org_name LIKE '%$org_name%'";
if ($area != 'All') {
$sql_result .=" AND area LIKE '%$area%'";
}
if ($services != 'All') {
$sql_result .=" AND services LIKE '%$services%'";
}
if ($hardiker != 'All') {
$sql_result .=" AND hardiker = '$hardiker'";
}
//echo result and order by name
$sql_result .=" ORDER BY org_name";
//echo $sql_result;
$result = mysql_query($sql_result, $dbh) or die ('Database currently being updated, please try again later!');
$num=mysql_numrows($result);
//echo $sql_result;
//get the count
echo '<h3><span style="color: #000; font-weight:bold">Total search results: </span>'.$num.'</h3><br/>';
if ($num > 0)
{
?>
I desperaty need help in how I can add to the query above to allow the option selected displayed along with the other if statements. Many thanks in advance!