Jump to content


Photo

PHP Searching for one field in more than one table....


  • Please log in to reply
2 replies to this topic

#1 GremlinP1R

GremlinP1R
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationSouth Africa

Posted 10 October 2006 - 08:10 AM

Hi There All.

I'm doin a script with an advance search function but are batteling to get working. Every thing are working 100% except this one field. In the data base I have a Company1 - Company0 thats equil to Company10.
Now for my search I need to search for a spesific field in all ten tables, or must I call them rows?
Okay this is what I have.....

// Get all the data from the "Users" table
  if ($select == Company){$result = mysql_query("SELECT * FROM individuals WHERE Company* LIKE ('%$for%') AND `Active` = 0 ORDER BY Surname ASC ");}
  else {
  $result = mysql_query("SELECT * FROM individuals WHERE $select LIKE ('%$for%') AND `Active` = 0 ORDER BY Surname ASC ");}

There on the first line is my problem, where it says Company*, Now I have treid making it % and I have treid to put in more than one but then I just get errors! Can any one please help!

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 10 October 2006 - 09:30 AM

As far as I'm aware you can't use '*' wildcards for column names in a 'where' clause... use 'or'

"SELECT * FROM individuals WHERE Company1 LIKE ('%$for%') OR Company2 LIKE ('%$for%') OR Company3 LIKE ('%$for%')...

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 GremlinP1R

GremlinP1R
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationSouth Africa

Posted 10 October 2006 - 09:36 AM

Oh Thanx HuggieBear.

Your a life saver, Have treid or but done it the wrong way. But its working now thanx!

Regards Gremlin




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users