LIKE and variable (beginner)
LIKE and variable (beginner)
am 29.03.2006 23:23:00 von stewartgriffin
hey all:
wondering if something is wrong with my syntax
when i use WHERE and =, and use a variable in php the code returns
what i want but when i use a variable like below and type in a portion
of a word it should find, nothing is returned
here is code:
$searchname = $_POST['searchname'];
mysql_connect('mysql24.secureserver.net',$username,$password );
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM restaurant_list
WHERE rest_name LIKE '%$searchname%'";
thanks in advance
Re: LIKE and variable (beginner)
am 31.03.2006 05:34:44 von Stefan Rybacki
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
stewartgriffin schrieb:
> hey all:
> wondering if something is wrong with my syntax
> when i use WHERE and =, and use a variable in php the code returns
> what i want but when i use a variable like below and type in a portion
> of a word it should find, nothing is returned
>
> here is code:
>
> $searchname = $_POST['searchname'];
>
> mysql_connect('mysql24.secureserver.net',$username,$password );
> @mysql_select_db($database) or die( "Unable to select database");
>
> $query="SELECT * FROM restaurant_list
> WHERE rest_name LIKE '%$searchname%'";
>
> thanks in advance
>
Well my cristal ball is broken.
More input please!
Regards
Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (MingW32)
iD8DBQFELKNUyeCLzp/JKjARAsRUAKCY/icrkB41k6gkx+RzOB25cm9uYQCe KCcr
7p19VbC0IyYePJpp9savObc=
=huQ1
-----END PGP SIGNATURE-----
Re: LIKE and variable (beginner)
am 03.04.2006 15:47:21 von Roger Dodger
Try
$query="SELECT * FROM restaurant_list WHERE rest_name LIKE
'%".$searchname."%' ";
Re: LIKE and variable (beginner)
am 04.04.2006 06:34:26 von Stefan Rybacki
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Roger Dodger schrieb:
> Try
>
> $query="SELECT * FROM restaurant_list WHERE rest_name LIKE
> '%".$searchname."%' ";
>
Where is the difference to what the OP had?
curious regards
Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (MingW32)
iD8DBQFEMfdSyeCLzp/JKjARAlnNAJwKZqhvB6BJHzleEnngBraKQ7nQYwCf Q7CG
Ua0q78CQ1+b9adnnJhJahqM=
=3naH
-----END PGP SIGNATURE-----
Re: LIKE and variable (beginner)
am 04.04.2006 18:09:22 von Roger Dodger
Stefan Rybacki wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Roger Dodger schrieb:
> > Try
> >
> > $query="SELECT * FROM restaurant_list WHERE rest_name LIKE
> > '%".$searchname."%' ";
> >
>
> Where is the difference to what the OP had?
>
> curious regards
> Stefan
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.1 (MingW32)
>
> iD8DBQFEMfdSyeCLzp/JKjARAlnNAJwKZqhvB6BJHzleEnngBraKQ7nQYwCf Q7CG
> Ua0q78CQ1+b9adnnJhJahqM=
> =3naH
> -----END PGP SIGNATURE-----
To be honest, there really isn't a difference. However, when I cut and
pasted his code, it didn't work for me either. I made that change, and
then started receiving results. Strangely enough, when I reverted to
his original syntax, I STILL was receiving results. So I really don't
know what the problem was. I've found, though, that when dealing with
embedded single quotes and double quotes, it's just easier for me to
make explicit what I want to print out by using concatenation
operators. Personal preference really.