[SOLVED] sql query error after if statment
Posted: Fri Oct 21, 2005 8:43 am
Hi all,
executing this query.
if i getSuburb is true or one of the following the first $query = 0
so wont work
any ideas?
executing this query.
if i getSuburb is true or one of the following the first $query = 0
so wont work
any ideas?
Code: Select all
<?php
error_reporting (E_ALL);
$query =" SELECT suburb, location, address1, address2, address, address3, crossst, ubd, crew, dns, " .
" facility, frequency, antenna, txpolarity, txpower, receiver, " .
" hornbearing, rxpolarity, rxpower, comms_id, commsnotes, contactname, " .
" contactcompany, contactno, contactemail, setupdetails, safetynote, " .
" comments, user_name, surveydatetime, atnid, postcode, " .
" whereisurl, repeater, freqother, date, lat, lng, satlng " .
" FROM locations " .
" WHERE state = '" . $getState . "' " ;
if($getSuburb!='') {
$query = $query + " AND suburb like '" . $getSuburb . "%' " ;
}
if($getLocation != '') {
$query = $query + " AND location like '" . $getLocation . "%' " ;
}
if($getAddress != '') {
$query = $query + " AND address like '" . $getAddress . "%' " ;
}
if($getAddress2 != '') {
$query = $query + " AND address2 like '" . $getAddress2 . "%' " ;
}
if($getCrossst != '') {
$query = $query + " AND crossst like '" . $getCrossst . "%' " ;
}
if($getUbd != '') {
$query = $query + " AND ubd like '" . $getUbd . "%' " ;
}
if($getContactName != '') {
$query = $query + " AND contactname like '" . $getContactName . "%' " ;
}
if($getContactCompany != '') {
$query = $query + " AND contactcompany like '" . $getContactCompany . "%' " ;
}
$results=mysql_query($query) or die('Could not execute query because: ' . $query . ' ' . mysql_error());
while ($row=mysql_fetch_array($results))
{
extract ($row);
?>