searching strings

  • iochinome
  • Beginner
  • Beginner
  • iochinome
  • Posts: 42

Post 3+ Months Ago

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
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

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...
  • argrafic
  • Beginner
  • Beginner
  • argrafic
  • Posts: 53

Post 3+ Months Ago

I have used:

Code: [ Select ]
SELECT * FROM table WHERE column LIKE '$string'
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

argrafic wrote:
I have used:

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

You can use either way
  • iochinome
  • Beginner
  • Beginner
  • iochinome
  • Posts: 42

Post 3+ Months Ago

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
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

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
  • iochinome
  • Beginner
  • Beginner
  • iochinome
  • Posts: 42

Post 3+ Months Ago

oh cool thankyou so much i never know you could do that.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

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

Yeah, no problem :) Glad we could help :D

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 38 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
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.