Querying Database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gazkee
Forum Newbie
Posts: 5
Joined: Sat Apr 20, 2002 1:10 am
Location: New Zealand

Querying Database

Post 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.. :?
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post 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.
gazkee
Forum Newbie
Posts: 5
Joined: Sat Apr 20, 2002 1:10 am
Location: New Zealand

Post 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?
Post Reply