Jump to content


Photo

searching more than one field


  • Please log in to reply
7 replies to this topic

#1 Radioactive Frog

Radioactive Frog
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationEngland

Posted 18 December 2003 - 09:42 AM

i have this query for searching one field

SELECT * FROM `hotels` WHERE hotelname LIKE \'%j%\'

at it works ok, but i would like to search say two more fields i thought it would be like below but that dont work :( please could someone point out where i am going wrong....thanks
SELECT * FROM `hotels` WHERE hotelname OR hotelcountry OR hoteladdress LIKE \'%j%\'

thanks
[a href="http://www.wildhosting.co.uk" target="_blank"]Wild Hosting[/a] :: [a href="http://www.brandstar.co.uk" target="_blank"]Brandstar UK Ltd[/a]

#2 Tmic

Tmic
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 December 2003 - 11:03 AM

more like this:

select * from hotels where \' *j%\' in (hotelname,hotelcountry,hoteladdress);

#3 Radioactive Frog

Radioactive Frog
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationEngland

Posted 18 December 2003 - 11:55 AM

that doesnt show any results when i test it in phpmyqdmin :(
[a href="http://www.wildhosting.co.uk" target="_blank"]Wild Hosting[/a] :: [a href="http://www.brandstar.co.uk" target="_blank"]Brandstar UK Ltd[/a]

#4 Tmic

Tmic
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 December 2003 - 12:18 PM

sry the second * must be % ofcourse

this works on my system but I don\'t use phpadmin

#5 Radioactive Frog

Radioactive Frog
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationEngland

Posted 18 December 2003 - 12:47 PM

yeah i had changed that, sorry i should have saidm but it doesnt make any difference :(
[a href="http://www.wildhosting.co.uk" target="_blank"]Wild Hosting[/a] :: [a href="http://www.brandstar.co.uk" target="_blank"]Brandstar UK Ltd[/a]

#6 nabeel21

nabeel21
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 18 December 2003 - 01:33 PM

SELECT * FROM hotels WHERE hotelname LIKE \'%j%\' OR hotelcountry LIKE \'%j%\' OR hoteladdress LIKE \'%j%\'

and make sure that the data in mysql table is all lowercase, cuz you are using \"j\".

goodluck

#7 Radioactive Frog

Radioactive Frog
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationEngland

Posted 18 December 2003 - 02:25 PM

thanks i will try it, j is only a test to see if it works i will put a \'%$search%\' there when i put it on the php page !!

thanks again
[a href="http://www.wildhosting.co.uk" target="_blank"]Wild Hosting[/a] :: [a href="http://www.brandstar.co.uk" target="_blank"]Brandstar UK Ltd[/a]

#8 Radioactive Frog

Radioactive Frog
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationEngland

Posted 18 December 2003 - 04:46 PM

great that works for that, but what about if i had to search variables coming in? how would i incorporate that? i have tried a couple of things but they dont work :(

any ideas?

thanks again
[a href="http://www.wildhosting.co.uk" target="_blank"]Wild Hosting[/a] :: [a href="http://www.brandstar.co.uk" target="_blank"]Brandstar UK Ltd[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users