Re: Another newbie question -- ANSWERED!!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 6 Sep 2004, Pete Holsberg wrote:

> The following code results in the error message "Couldn't
> execute query."

> $sql = "SELECT * FROM $table ";
> $sql .= "WHERE `LastName` LIKE $search_string ";
> $sql .= "OR `FirstName` LIKE $search_string ";
> $sql .= "OR `Spouse` LIKE $search_string ";
> $sql .= "OR `Street` LIKE $search_string ";
> $sql .= "OR `Email` LIKE $search_string LIMIT 0, 30 ";
> $sql .= "ORDER BY Street, HouseNum, LastName";


Here's the query string that worked:

$sql = "SELECT * FROM $table ";
$sql .= "WHERE `LastName` LIKE` '%$search_string%' ";
$sql .= "OR `FirstName` LIKE '%$search_string%' ";
$sql .= "OR `Spouse` LIKE '%$search_string%' ";
$sql .= "OR `Street` LIKE '%$search_string%' ";
$sql .= "OR `Email` LIKE '%$search_string%' ";
$sql .= "ORDER BY Street, HouseNum, LastName";


With a Unix shell programming background, I'm puzzled by
the use of 'tics' (single quotes, apostrophes' around
%$search_string%. I would have though that they would have
removed the special meaning of the $.

Also, should I have back tics around a column name
EVERYWHERE it's used in a SELECT (in this case, following
ORDER)?

Thanks.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux