MySQL Search

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

MySQL Search

Post by mhouldridge »

Hi,

I need to search all my colums within my software table using the search post;


Here is my query;

Code: Select all

$result = mysql_query("SELECT * FROM software WHERE $array LIKE '%$search%' ORDER BY id");

I created an array with my colum names however this is not working.

Does anybody know howto do this.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

you cannot echo an array, you can only echo strings, floats or integers. :)

In other words, you need to take your column headings out of the array and insert them into the query string :)
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

my column headings are id, publisher, name and version;

I tried this, however it did not work;

$result = mysql_query("SELECT * FROM software WHERE 'id', 'publisher', 'name', 'version' LIKE '%$search%' ORDER BY id");
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

WHERE `id` LIKE '%{$search}%' OR `publisher` LIKE '%{$search}%' etc. :)
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Ok...

But if I want to check all of these values with this query?
Post Reply