[SOLVED] sql query error after if statment

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
FREESTYLER
Forum Newbie
Posts: 17
Joined: Tue Oct 18, 2005 10:33 am

[SOLVED] sql query error after if statment

Post by FREESTYLER »

Hi all,

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);
?>
Last edited by FREESTYLER on Fri Oct 21, 2005 11:00 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're thinking string concatenation is +, when it is a . in php.
FREESTYLER
Forum Newbie
Posts: 17
Joined: Tue Oct 18, 2005 10:33 am

Post by FREESTYLER »

feyd wrote:you're thinking string concatenation is +, when it is a . in php.
thank you ur a damn legend
im new to php came from java so had a guess
didnt even think about the . after using it so much
plus im drunk now
Post Reply