PDA

View Full Version : Help with a MySQL search query.



gokujou
April 8th, 2008, 07:19 PM
Hello,
I am trying to make a search that will look into multiple fields in my mysql table but all I have got to work so far is this that one searches one field.



$query = "SELECT * FROM ln_establishments WHERE est_name LIKE '%".$_POST['search_term']."%' ";


I have also tried doing a "WHERE est_name, est_desc" but no luck there so it must not be correct syntax. Any help or pointers would be awesome. Thank you!

Icy Penguin
April 8th, 2008, 07:26 PM
$query = "SELECT * FROM ln_establishments, other_file_name, another_field_name WHERE est_name LIKE '%".$_POST['search_term']."%' ";

gokujou
April 8th, 2008, 11:07 PM
But that is for multiple tables with the same field if I understand it correct. Right?

Icy Penguin
April 9th, 2008, 02:35 AM
Wow - brain fart.

The * (after SELECT) refers to your fields - the ln_establishments and such are your tables.

The asterisk means you're selecting all fields from those tables.

So, to select one or two fields from a table:



SELECT field1, field2 FROM table_2, table_666 WHERE....