How can I attach % to a $variable in a query_string?

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
johncal
Forum Newbie
Posts: 2
Joined: Fri Mar 19, 2004 1:43 pm

How can I attach % to a $variable in a query_string?

Post by johncal »

Hello All,
Thanks in advance for reading this.

I am trying to use 'like' in a query_string for mysql,
but can't seem to incorporate the % properly.

For example, the actual sql is:
SELECT * FROM table WHERE date like '1999%'
(Needless to say it brings back all entries for 1999)

So, I need to construct a query string out of this, however the date
(which is formated in the table as yyyy-mm-dd) is a variable

for example:
$query_string = "SELECT * FROM table WHERE date like '$date'

HOW do I attach the % to the variable $date in this string?

thanks !

John[/b]
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

$date%

have u tried that??
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

Code: Select all

$query_string = "SELECT * FROM table WHERE date LIKE '".$date."%'"
Post Reply