What's the difference, and is it possible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NATASHALUX55
Forum Newbie
Posts: 3
Joined: Thu Jun 25, 2009 5:52 am

What's the difference, and is it possible?

Post by NATASHALUX55 »

$query = 'SELECT * FROM `products` WHERE `descript` LIKE (\'%girl%\')';
If the code above is written into the php script and I run through the browser: mysite.com/search.php
I get a list of products with the word "girl" in the 'descrip'tion

If I change the code to this:
$query = 'SELECT * FROM `products` WHERE `descript` LIKE (\'%.$newSearch.%\')';
or this:
$query = 'SELECT * FROM `products` WHERE `descript` LIKE (\'%.$_GET["newSearch"].%\')'
then go here:
mysite.com/search.php?newsearch=girl
I get no errors but I get no results either, just blank

any help or explanation would be great...
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: What's the difference, and is it possible?

Post by jaoudestudios »

Try this...

Code: Select all

$query = 'SELECT * FROM `products` WHERE `descript` LIKE "%'.$_GET["newSearch"].'%"';
NB: Dont forget to protect your database!
coolpositive
Forum Newbie
Posts: 4
Joined: Sat Jun 07, 2008 6:13 am

Re: What's the difference, and is it possible?

Post by coolpositive »

Hi NATASHALUX55

when you write query in php then echo theat query on page then copy that query and and direct paste on sql mode of phpmyadmin or what every use your database.

you got the exect error what is the problem in your query.
NATASHALUX55
Forum Newbie
Posts: 3
Joined: Thu Jun 25, 2009 5:52 am

Re: What's the difference, and is it possible?

Post by NATASHALUX55 »

jaoudestudios wrote:Try this...

Code: Select all

$query = 'SELECT * FROM `products` WHERE `descript` LIKE "%'.$_GET["newSearch"].'%"';
NB: Dont forget to protect your database!
Well I got results... But it was all products that was listed...
does LIKE %***% not work like that? Anyway thanks for your help so far- I was happy just to see something.

I have to entries I'm using as my test, they both have cuddly in the descript and 1 has boy and 1 has girl in the descript.

http://giftsbyfairfields.com/newsearch. ... hTerm=girl
has no effect on narrowing the search.
I'm thinking maybe it's not as simple as that and that's why I'm having issues?

again- thanks
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: What's the difference, and is it possible?

Post by mattpointblank »

You capitalised the S in 'newSearch' in the code, but not in the URL.
NATASHALUX55
Forum Newbie
Posts: 3
Joined: Thu Jun 25, 2009 5:52 am

Re: What's the difference, and is it possible?

Post by NATASHALUX55 »

it worked... one more question...

WHY DIDN'T I COME HERE SOONER???

Thanks a whole bunch, I hope one day to return the favor to someone who's stuck. :D
Post Reply