For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > April 2006 > LIKE and variable (beginner)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author LIKE and variable (beginner)
stewartgriffin

2006-03-29, 6:59 pm

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

Stefan Rybacki

2006-03-30, 9:58 pm

-----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+RzOB25cm9uYQCeKCcr
7p19VbC0IyYePJpp9savObc=
=huQ1
-----END PGP SIGNATURE-----
Roger Dodger

2006-04-03, 7:00 pm

Try

$query="SELECT * FROM restaurant_list WHERE rest_name LIKE
'%".$searchname."%' ";

Stefan Rybacki

2006-04-04, 3:59 am

-----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/ JKjARAlnNAJwKZqhvB6BJHzleEnngBraKQ7nQYwC
fQ7CG
Ua0q78CQ1+b9adnnJhJahqM=
=3naH
-----END PGP SIGNATURE-----
Roger Dodger

2006-04-04, 6:59 pm


Stefan Rybacki wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Roger Dodger schrieb:
>
> Where is the difference to what the OP had?
>
> curious regards
> Stefan
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.1 (MingW32)
>
> iD8DBQFEMfdSyeCLzp/ JKjARAlnNAJwKZqhvB6BJHzleEnngBraKQ7nQYwC
fQ7CG
> 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.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com