From: "Pete Holsberg" <pjh@xxxxxxxx>
$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 $.
The single quotes around the search string are necessary to define the string. You can use double or single quotes, really, so long as you're making a string. Without the quotes, the database will think it's a column name.
Also, should I have back tics around a column name EVERYWHERE it's used in a SELECT (in this case, following ORDER)?
Backticks are not required anywhere, really, in this case. When they are required is when you have a column name that is either a reserved word or has special characters in it. If this is MySQL, it'll allow you to have column named called "order", "desc", "foo bar", etc, and not complain during the table creation. It will complain when it hits those reserved words in the queries, though, so that's why you use the backticks.
---John Holmes...
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php