Page 1 of 1

Querying Database

Posted: Fri May 24, 2002 11:23 pm
by gazkee
Hey there :!: :!: Just a query regarding commands used for MYSQL.

I have on a form 3 fields, 1 list, 1 text and 1 submit/search button. Once the form has been submitted, what commands would be used to query the database depending on which type was chosen from the list menu, and the data inputted in the text field.

eg The list has Singer, Album, Song. And the text field is where you'd type in details of what ever your looking for, and the search button will post the form to the .php file containing sql commands.

Really appreciate some advice.. Cheers.. :?

Posted: Sat May 25, 2002 7:49 am
by MattF

Code: Select all

<?
$result = mysql_query("SELECT * FROM table WHERE $list LIKE '%$text_box%'");

while($row=mysql_fetch_array($result))
{
echo "$rowї1]<br>";
}
?>
I'm not sure about the LIKE bit because I haven't used it for a while, just make sure your drop down list has the three field names in it as the options.

Posted: Sat May 25, 2002 5:51 pm
by gazkee
Thanks Matt, I'll have a go of it today and see how it goes.. I've used the LIKE function before, and have tested it having data in the tables that are similar, but it only displays one row, to display all of the near matches is that what the fetch_array is used for?