I have four drop down boxes.. author,year,genre and publisher.If I click on all 4 boxes it works fine,so I could see what books an author wrote in any year,and this is accompanied by the genre and publisher. I also get a result if I just click on one box.For example if I click on "adventure" in the genre box,I get all the records for adventure.Likewise with the other boxes individually. So the boxes are working together and individualy.My problem arises when i try and click just two(or three) boxes ie if I just wanted author and publisher,or genre,year and publisher.All suggestion much appreciated🙂
<html>
<head>
<title>My Page</title>
</head>
<body>
<br>
<form name="myform" action="dropdown3.php" method="POST">
<select name="author" size="4">
<option value="ken davies">ken davies</option>
<option value= "arthur smith">arthur smith</option>
<option value="gill rafferty">gill rafferty</option><br />
<option value="molly brown">molly brown</option><br />
<option value="gilbert riley">gilbert riley</option><br />
<input type = "submit" name = "submit" value = "go">
<select name="genre" size="4">
<option value="adventure">adventure</option>
<option value="biography">biography</option>
<option value="crime">crime</option><br />
<option value="romance">romance</option>
<option value="2007">thriller</option>
<input type = "submit" name = "submit" value = "go">
<select name="year" size="4">
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<input type = "submit" name = "submit" value = "go">
<select name="publisher" size="4">
<option value="blue parrot">blue parrot</option>
<option value="yonkers">yonkers</option>
<option value="zoot">zoot</option>
<input type = "submit" name = "submit" value = "go">
<?php
$bird = ( ! empty($_POST['author'])) ? $_POST['author'] : null;
$cat = ( ! empty($_POST['genre'])) ? $_POST['genre'] : null;
$mouse = ( ! empty($_POST['year'])) ? $_POST['year'] : null;
$goat = ( ! empty($_POST['publisher'])) ? $_POST['publisher'] : null;
//NEXT CONNECT TO DATABASE
//------------------------------------------------------------------
//echo $bird;
$con = mysql_connect("localhost","root","");
If (!$con){
die("Can not Connect with database" . mysql_error());
}
Mysql_select_db("authors",$con);
if (isset($bird) && isset($cat) && isset($mouse) && isset($goat))
{
$sql = "SELECT * FROM books WHERE author = '$bird' AND genre = '$cat' AND year= '$mouse' AND publisher = '$goat' ";
}
else if (isset($bird))
{
$sql = "SELECT * FROM books WHERE author = '$bird' ";
}
else if (isset($cat))
{
$sql = "SELECT * FROM books WHERE genre = '$cat' ";
}
else if (isset($mouse))
{
$sql = "SELECT * FROM books WHERE year = '$mouse' ";
}
else if (isset($goat))
{
$sql = "SELECT * FROM books WHERE publisher = '$goat' ";
$myData = mysql_query($sql,$con);
echo"<table border=1>
<tr>
<th>id</th>
<th>author</th>
<th>title</th>
<th>publisher</th>
<th>year</th>
<th>genre</th>
<th>sold</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<tr>";
echo "<td>" . $record['id'] . "</td>";
echo "<td>" . $record['author'] . "</td>";
echo "<td>" . $record['title'] . "</td>";
echo "<td>" . $record['publisher'] . "</td>";
echo "<td>" . $record['year'] . "</td>";
echo "<td>" . $record['genre'] . "</td>";
echo "<td>" . $record['sold'] . "</td>";
echo "<tr />";
}
echo "</table>";
mysql_close($con);
?>
all four are working<br />
all work individually<br />
two or three dont work together
</form>
</body>
</html>