To make it somewhat easier, you could make an array of the column names, then form a loop which ties the column names into a string. This string could then be put into mysql_query() for execution.
Example:
PHP Code:
<?php
// search query
$search = "dogs";
// table name
$table = "tableName";
// column names
$c = array(
"column0",
"column1",
"column2",
"column3",
"column4"
);
// mysql query string
$str = "SELECT * FROM `{$table}` WHERE ";
// ties in columns with mysql query string
for($i = 0; $i < count($c); $i++) {
if($i == (count($c)-1)) { $str .= ("`{$c[$i]}` = '{$search}'"); }
else { $str .= ("`{$c[$i]}` = '{$search}' OR "); }
}
// executes the mysql query string (uncomment to execute)
// mysql_query($str);
// echoes query string
echo $str;
?>
But, as you guys said, it may be bad deisign...
Bookmarks