help with dropdown menu searching

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hawkontvn
Forum Newbie
Posts: 4
Joined: Tue May 11, 2010 12:46 pm

help with dropdown menu searching

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