Page 1 of 1

help with dropdown menu searching

Posted: Thu May 13, 2010 2:17 pm
by hawkontvn
hey need some help here :)

created a dropdown menu populated by a 'category'-table from my database.
code:

[syntax]<?php
$query = "SELECT categoryID AS ci,
categoryName AS cn FROM category
ORDER BY categoryName";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result))
{
$id = $row['ci'];
$cat = $row['cn'];
$options.="<option value='$id'>".$cat."</option>";
}
?>

<form method="get" action="/biblio/">
<select name="showcat">
<option value="">
Choose category
<?=$options?>
</option>
</select>
<input type="submit" value="Search" />
</form>[/syntax]

Now the dropdown menu is working, but im trying to have it print out all books in the particular category i selected.

Code so far:
[syntax]<?php
$list_cats = mysql_query("SELECT * FROM category
ORDER BY categoryName;");

while($row = mysql_fetch_array($list_cats))
{
$cid = $row['categoryID'];
$cname = $row['categoryName'];
}

if($_GET['showcat'])
{
$cid = $_GET['showcat'];
$cname = $_GET['showcat'];

echo "<br /><p><b>Books in picked category:</b></p>";

$query = "SELECT * FROM category
WHERE categoryName = $cname";

$res = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($res))
{
$cid = $row['categoryID'];
$cname = $row['categoryName'];
}

}

?>[/syntax]

Thanks.