Re: Another newbie question -- ANSWERED!!
| From: | Pete Holsberg | Date: | Tue, 07 Sep 2004 17:16:20 +0000 |
| Subject: | Re: Another newbie question -- ANSWERED!! | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-36094@lists.php.net to get a copy of this message | ||
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.