Jump to content


Photo

Searching mysql database for 2 variables


  • Please log in to reply
2 replies to this topic

#1 boyx

boyx
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 20 April 2006 - 08:51 AM

I have a database that i can search for one variable,
now i would like it to match a first variable and a second in order to return a result,

II have this at the moment:

$query = "SELECT *
       FROM  `pbx`
       WHERE  `swlevel` LIKE '$keyword%' AND `vm`='$keyword2%'";

So keyword one checks swlevel and keyword 2 checks vm entry
problem is it seems to return mixed results,

I have one which is 23 and yes
and one that is 24 and none, but it returns both rows as valid results ...

Any hints or ideas? just getting used to this stuff.

#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 20 April 2006 - 09:02 AM

In my clients table, i have two clients whose company name contains 'afon'.

So, if i were to run: "SELECT * FROM clients WHERE company LIKE '%afon%'" it would return two results.

However, if i run: "SELECT * FROM clients WHERE company LIKE '%afon%' AND client_id = '2'" this will return only the one result.

This does work... as i am using it right now.

wisewood: proven fact, I am both wise, and wooden.

#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 20 April 2006 - 09:03 AM

my best guess would be that $keyword2 is undefined in this case, making it match anything in the second clause. what was being passed?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users