Hi there,
Im trying to create a script that will allow you to search a database using various search terms (Ward, Party, Name, Ward Party, Ward Name, Ward Party Name, Party Name).
I was unsure how to run the query, do I need to create a seperate mysql query for each of the search variations.
I have posted what I have done so far below, and I was hoping for soem advice before I plod on with coding it up.
<?php // This is the hone page for the site.
// set the title for the html header
$page_title = 'Results';
// require the config file
require_once ('../includes/config.inc.php');
// include the header filde
// add header file once created
// require the database settings file using information from config.inc.php
require_once (MYSQL);
// get the variables posted from the form in the url and clean before using it in a query
$ward = mysqli_real_escape_string ($dbc, trim($_GET['ward']));
$party = mysqli_real_escape_string ($dbc, trim($_GET['party']));
$name = mysqli_real_escape_string ($dbc, trim($_GET['name']));
// trim any whitespace from the free text field
$name_trimmed = trim($name);
// check for emply field to select the correct query
// This performs a seach if a user only searches by ward
if ($trimmed == "" && $party == '*'){
// query tables using the cleaned values posted from the form - ward
$q="SELECT name.cllr_id, name.first_name, name.surname, name.address_id, name.phone, name.email, name.party_id, name.ward_id, name.image FROM name WHERE (name.ward_id = $ward)";
// For debugging return any errors or run the query
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
// get the data ready to output into a table and query aginst the address, party and ward tables.
$rows=mysqli_fetch_array($r);
// query the address, party and ward tables using the vaules from the last query
$q2="SELECT * FROM address, party, ward WHERE (name.ward_id = ward.ward_id) AND (name.party_id = party.party_id) AND (name.address_id = address.address_id)";
// get the data ready to output into a table and query aginst the address, party and ward tables.
$rows=mysqli_fetch_array($r);
} elseif
// will run a number of queries depending on what criteria has been searched for.