maxudaskin Posted July 25, 2007 Share Posted July 25, 2007 Is it possible to select from a table using WHERE without putting in a column name? Kind of like this: mysql_query("select * from flights WHERE LIKE '{$searchfield}'"); Quote Link to comment Share on other sites More sharing options...
Barand Posted July 25, 2007 Share Posted July 25, 2007 No Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 25, 2007 Share Posted July 25, 2007 What did you hope you would achieve by searching in this way? If you tell us what you are actually trying to do, we might be able to tell you a way of doing it. Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted July 25, 2007 Author Share Posted July 25, 2007 I was hoping to have it so that when somone searches, it will select that from any column instead of just one. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted July 25, 2007 Share Posted July 25, 2007 Maybe this is what your looking for: mysql_query("select * from flights WHERE colum1 LIKE '{$searchfield}' AND colum2 LIKE '{$searchfield}' AND colum3 LIKE '{$searchfield}' AND colum4 LIKE '{$searchfield}'"); Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted July 25, 2007 Author Share Posted July 25, 2007 Maybe this is what your looking for: mysql_query("select * from flights WHERE colum1 LIKE '{$searchfield}' AND colum2 LIKE '{$searchfield}' AND colum3 LIKE '{$searchfield}' AND colum4 LIKE '{$searchfield}'"); So... mysql_query("select * from flights WHERE colum1 LIKE '{$searchfield}', colum2 LIKE '{$searchfield}', colum3 LIKE '{$searchfield}', colum4 LIKE '{$searchfield}'") ? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted July 25, 2007 Share Posted July 25, 2007 oh... yeah... I forgot the commas, but yea something like that. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 25, 2007 Share Posted July 25, 2007 You'd want OR and not AND if you want ro search for the value in any column. If you use AND, it has to be in EVERY column $result = mysql_query("select * from flights WHERE (column1 LIKE '%$searchfield%') OR (column2 LIKE '%$searchfield%') OR (column3 LIKE '%$searchfield%') OR (column4 LIKE '%$searchfield%') "); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.