Forum Moderators: open
I am a newbie to this forum - have been learning php recently (& posted to that forum). I have some knowledge of mySQL but my queries are these:
I have a database that holds info for CDs (this is for a prototype website I'm designing) - anyway, database is populated with tables - e.g. Artist, Type, Wishlist etc. etc. I have set up a page where user can search the CD catalogue using the following options:
a) Year of release of CD. b) Price (between 1 - 9.99..) c) Artist name,
I've set up the form and for the first dropdown box - it works okay and gives results back from dbase. However, when I try to AND the second drop-down - it doesn't seem to work... (I'm working on the coding at the mo. to see if I can re-work that).
But I'm stuck trying to figure out the SQL for the following:
1) Letting the user choose from about 4 different menus (drop down boxes)
2) Having a checkbox option that user can also use to create a compound query using all options to get result from dbase.
3) Also not to sure about how to do the min and max values for the price (I think they will need to have 2 drop downs for this).
Anyway, that is basically the gist of the whole thing - I am not mySQL savvy enough to do the select queries - ANY HELP = much appreciated.
Here is the coding I'm currently using - (without the checkbox option)
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
$link = mysql_connect("localhost","","");
mysql_select_db("createdb1", $link) or die("Unable to select database");
$selectSql = "SELECT * FROM film WHERE releaseyear = '".mysql_real_escape_string($_POST['releaseyear'])."'
AND price = '".mysql_real_escape_string($_POST['price'])."'";
echo $selectSql;
$result = mysql_query($selectSql, $link) or die(mysql_error());
if (($result)¦¦(mysql_errno == 0))
{
echo "<table width='100%'><tr>";
if (mysql_num_rows($result)>0)
{
//loop thru the field names to print the correct headers
$i = 0;
while ($i < mysql_num_fields($result))
{
echo "<th>". mysql_field_name($result, $i) . "</th>";
$i++;
}
echo "</tr>";
//display the data
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr>";
foreach ($rows as $data)
{
echo "<td align='center'>". $data . "</td>";
}
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
}
echo "</table>";
}else{
echo "Error in running query :". mysql_error();
}
?>