Re: Search Query on two tables not working

From: Date: Tue, 21 Jul 2009 16:41:22 +0000
Subject: Re: Search Query on two tables not working
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-295629@lists.php.net to get a copy of this message
Turned off the redirects on the whole script and tried to the the query to echo and these are the errors I got: Notice: Undefined offset: 1 in /var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.php on line 89 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.php on line 119 On 7/21/09 11:32 AM, "Kevin Smith" <kevin@netsmith.ltd.uk> wrote: Can you supply the actual generated SQL, I can potentially see a problem, but need to see the final SQL statement. Miller, Terion wrote: > Why isn't this working for searching? > > // Run query on submitted values. Store results in $SESSION and redirect to restaurants.php > $sql = "SELECT name, address, inDate, inType, notes, critical, cviolations, noncritical > FROM restaurants, inspections WHERE restaurants.name<> '' AND restaurant.ID = > inspection.ID"; if ($searchName) { $sql .= "AND restaurants.name LIKE > '%". mysql_real_escape_string($name) ."%' "; if(count($name2) == 1) > { $sql .= "AND restaurants.name LIKE '%". > mysql_real_escape_string($name2[1]) ."%' "; } else { foreach($name2 > as $namePart) { $sql .= "AND restaurants.name LIKE '%". > mysql_real_escape_string($namePart) ."%' "; } } } if ($searchAddress) > { $sql .= "AND restaurants.address LIKE '%". > mysql_real_escape_string($address) ."%' "; } $sql .= "ORDER BY > restaurants.name;"; $result = mysql_query($sql); > >

« previous php.general (#295629) next »