Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-05-2011, 01:32 PM   PM User | #1
pquinn
New to the CF scene

 
Join Date: Mar 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
pquinn is an unknown quantity at this point
Searching for exact term or no result

Hello folks,

First time posting here and I am hoping some of you fine people could help me with a problem I am having.

I have a full text search box that if I type even the letter 'j' it will pull in every record with the letter 'j'.

Basically I cant figure out how to search for a term and only that term so if I type 'joe blogs' joes record will appear and if i type 'j' nothing will appear.

My apologies as I cant think of how to explain it.

The code I am using at the moment is:

//Search Query
$sql = mysql_query("SELECT * FROM UserList WHERE Name like '%$search%'");

Many Thanks,

Peter
pquinn is offline   Reply With Quote
Old 03-05-2011, 01:35 PM   PM User | #2
x34cha
New Coder

 
Join Date: Mar 2011
Posts: 57
Thanks: 5
Thanked 3 Times in 3 Posts
x34cha is an unknown quantity at this point
Quote:
Originally Posted by pquinn View Post
Hello folks,

First time posting here and I am hoping some of you fine people could help me with a problem I am having.

I have a full text search box that if I type even the letter 'j' it will pull in every record with the letter 'j'.

Basically I cant figure out how to search for a term and only that term so if I type 'joe blogs' joes record will appear and if i type 'j' nothing will appear.

My apologies as I cant think of how to explain it.

The code I am using at the moment is:

//Search Query
$sql = mysql_query("SELECT * FROM UserList WHERE Name like '%$search%'");

Many Thanks,

Peter
Probably a bit of a random guess, I'm new to PHP too, but where it says "name like" change it just to "name"
x34cha is offline   Reply With Quote
Old 03-05-2011, 01:41 PM   PM User | #3
pquinn
New to the CF scene

 
Join Date: Mar 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
pquinn is an unknown quantity at this point
lol now that does make me feel stupid, worked perfectly Thanks for helping
pquinn is offline   Reply With Quote
Old 03-05-2011, 01:46 PM   PM User | #4
x34cha
New Coder

 
Join Date: Mar 2011
Posts: 57
Thanks: 5
Thanked 3 Times in 3 Posts
x34cha is an unknown quantity at this point
Quote:
Originally Posted by pquinn View Post
lol now that does make me feel stupid, worked perfectly Thanks for helping
Hehe, no problem, sometimes common sence is all that is neccessary.
x34cha is offline   Reply With Quote
Old 11-22-2012, 04:08 PM   PM User | #5
valera
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
valera is an unknown quantity at this point
I have the same problem. Could you let me know how did you solved it? Thanks
valera is offline   Reply With Quote
Old 11-22-2012, 05:46 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You simply change the WHERE condition to not use like.
Code:
WHERE Name LIKE '%j%'
// becomes
WHERE Name = 'j'
This of course has nothing to do with PHP as this is a SQL issue in search criteria.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:29 PM.


Advertisement
Log in to turn off these ads.