Page 1 of 1

Search and display, from form

Posted: Wed Jun 04, 2008 2:04 pm
by lostprophetpunk
I am trying to create a search feature for my project.

Now, I have set up a form in HTML. I have give the various things (couple of text boxes and select options). I have given then names.

I have then sent the values over to another page.

I have then got the following to get the values from the database depending on what the user has typed in/selected in the form...

Code: Select all

 $query = "SELECT * FROM books WHERE Book_Title='$book' OR Author='$authors' OR Price='$price' OR Publication_Year='$year' OR Origin_Country='$origin' OR Condition='$condition'"; 
     
$result = mysql_query($query) or die(mysql_error());
 
 
while($row = mysql_fetch_array($result)){
    echo $row['Book_Title']. " - ". $row['Author'];
    echo "<br />";
}
I have checked and re-checked the variables I have stored the form values in, and they are correct...

Code: Select all

$book=$_POST['books'];
$authors=$_POST['author'];
$price=$_POST['price'];
$year=$_POST['year'];
$origin=$_POST['origin'];
$condition=$_POST['condition'];
I have also got the values in the '...' correct.

So how would I display the data in the database depending on what the user searches for.

Re: Search and display, from form

Posted: Wed Jun 04, 2008 3:04 pm
by RobertGonzalez
So what is not working? Are you getting errors? Can you post those errors?

Re: Search and display, from form

Posted: Thu Jun 05, 2008 12:23 am
by lostprophetpunk
I am not getting any errors, it's just that the whole of the data from the table displays. I only want the table to display data based on what the user searches for.

Such as if the user types in 'Angels & Demons', it would only display data about that book, and no other books.

Re: Search and display, from form

Posted: Thu Jun 05, 2008 10:22 am
by RobertGonzalez
Well you have about six different OR clauses in your query which is going to return a crap load of data. Try rewriting your query to be a little more specific to the search, or even consider using a full text search so you can match against a given term.