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!
Thanks for your help .. I found the script in a post on another forum ..
With the changes you suggested it is working alot better .. Altho it is displaying all the records in the "description" fields not just the ones containg the word used in the search ..
Say I type in samsung .. I only want it to return "description" fields that have the word samsung within that field .. Any idea on how to acheive this?
Even if you have a better script in mind to acheive this ..
I have no idea on search scripts .. and havnt found much around the net on how to create them.
Ausome, that works great .. Altho if I use "samsung" or "winbond Seitec" which are the fist word/s in the description field that works fine .. but if I search "256MB" which is a few words into the field it brings back no results... or search "PC2700" which is the next word after "samsung" .. Any idea on how to make it show results for the other words ie "PC2700"?
Also can u search across multuple tables or just one?
$db_query = "SELECT C_Memory.*, C_Audio.*, C_VGA.*FROM C_Memory,C_Audio,C_VGA WHERE C_Memory.description LIKE '%whatever%' OR C_Audio.description LIKE '%whatever%' OR C_VGA.description LIKE '%whatever%'";
Altho i wanted to add the price field as well which i had as:
Yes that is pretty much how you would do it although watch your spacing (you have the C_VGA.*FROM with no space before FROM which would cause an SQL error).
Doing this across 20 tables isn't ideal, but is still perfectly valid SQL. The only other way would be to create a temporary table by dragging in all of the fields from all of the tables you need and then searching that - but I wouldn't recommend it really.
//Build the SQL statement based on POST options
//The basic SQL will select all records
db_query = "SELECT C_Memory.*, C_Audio.*, C_VGA.*FROM C_Memory,C_Audio,C_VGA WHERE C_Memory.description LIKE '%whatever%' OR C_Audio.description LIKE '%whatever%' OR C_VGA.description LIKE '%whatever%'";
But it gives me an error on that line .. Also does the below code stay the same:
//depending on which of the following are filled in (none, some, all)
//the resultset returned will be filtered down
$desc = $_POSTї'description'];
if (strlen($desc) > 0) {
$db_query .= " WHERE description LIKE '%$desc%'";
}
Also where do i put the other fields so i can display those with the results .. I had:
The error is because of the thing I pointed out to you above (no space before FROM) and because you're appending that WHERE description block to the end of it - which is now invalid SQL.
You MUST get in the habit of echoing out the SQL query itself and also the results of mysql_error() - they will actually tell you what is wrong rather than just a random line number.
Your other fields are correct, put them there - but don't forget to extract them from the results, specifically:
<?=$row['description']?> - change that to the value to display
No, that's absolutely perfectly valid SQL - there is nothing wrong with it (other than in the missing $ from db_query, but I guess you just didn't select that part when pasting?)
Echo out $db_query right before you pass it to mysql_query and post it here, maybe it is being modified elsewhere in the code.