searching strings

  • iochinome
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Apr 12, 2008
  • Posts: 42
  • Status: Offline

Post May 21st, 2008, 9:11 am

hey guys, i watnt to add afeature to my website that allows people to search through a number of strings (usernames) for a word or first name or last name or somethign of the sort. how do websites accomplish things like this? thanks
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 21st, 2008, 9:11 am

  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 21st, 2008, 12:46 pm

It depends... are the stuff you are searching in MySQL? If so you can try something like...
PHP Code: [ Select ]
$sql = "SELECT * FROM `tblname` WHERE username = '%$query%'";
That's what I do anyway...
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • argrafic
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Dec 14, 2007
  • Posts: 53
  • Status: Offline

Post May 21st, 2008, 1:32 pm

I have used:

Code: [ Select ]
SELECT * FROM table WHERE column LIKE '$string'
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 21st, 2008, 1:35 pm

argrafic wrote:
I have used:

Code: [ Select ]
SELECT * FROM table WHERE column LIKE '$string'

You can use either way
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • iochinome
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Apr 12, 2008
  • Posts: 42
  • Status: Offline

Post May 21st, 2008, 7:03 pm

hmm... that sounds terrifically easy! i thought i was going to have to dick around with regular expressions or something like that. so what exactly does LIKE do?
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 21st, 2008, 8:30 pm

iochinome wrote:
hmm... that sounds terrifically easy! i thought i was going to have to dick around with regular expressions or something like that. so what exactly does LIKE do?

It allows you to use wildcards...

So, you can do something like...
Code: [ Select ]
$sql = "SELECT * FROM `table` WHERE `fieldName` LIKE '%$string%'";

The %...% allows you to search for employ in the word unemployment If you have $string% it would not find employ in unemployment but will find employ in employment... I think you get it...

Read more about it on techonthenet.com
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • iochinome
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Apr 12, 2008
  • Posts: 42
  • Status: Offline

Post May 22nd, 2008, 1:24 pm

oh cool thankyou so much i never know you could do that.
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 22nd, 2008, 1:41 pm

iochinome wrote:
oh cool thankyou so much i never know you could do that.

Yeah, no problem :) Glad we could help :D
"Bring forth therefore fruits meet for repentance:" Matthew 3:8

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 135 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.