Query by catagories - not working - HELP!!
Posted: Wed Jan 21, 2004 3:47 pm
Need help, I have been looking at this for the past few weeks, and cannot get it to work....
I have a query page that allows the user to search by category, or show all.
The show all works just fine, but the search by category will not work.
Here is my code:
So the above works, pulling the categories from the database into a dropdown.
However, as soon as one of the categories are selected, I get all categories.
Here is the result1.php
So where an I going wrong??
I have a query page that allows the user to search by category, or show all.
The show all works just fine, but the search by category will not work.
Here is my code:
Code: Select all
<?php
$query = "SELECT catID, category from category ORDER by catID";
$result = mysql_query($query)
or die ("Couldn't execute query.");
//create form containing selection list
echo '<form action="results1.php?catID='.$row['catID'].'" method="post"> <select name="category">'."\n";
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<option value='$category'>$category\n";
}
echo "</select>\n";
echo "<input type='submit' value='SELECT'>
</form>\n";
?>However, as soon as one of the categories are selected, I get all categories.
Here is the result1.php
Code: Select all
<?php
$query = "SELECT * FROM category ORDER BY catID";
$result = mysql_query( $query );
if ( $row = mysql_fetch_assoc( $result ) ) { // there are categories
do {
extract( $row );
$subquery = "SELECT positions.posID, positions.catID, positions.title, positions.tID, departments.departments, time.time
FROM positions, departments, time WHERE positions.depID = departments.depID AND positions.tID = time.tID AND catID=$catID";
$subresult = mysql_query( $subquery );
if ( $subrow = mysql_fetch_assoc( $subresult ) ) { // category has links
echo "<table>\n";
echo "<tr align="left"><th width="300"><font face="Verdana" size="1"><b>Position</b></font></th>
<th width="120"><font face="Verdana" size="1"><b>Time</b></font></th>
<th width="300"><font face="Verdana" size="1"><b>Department</b></font></th>
<th width="80"><font face="Verdana" size="1"><b>Go to Listing</b></font></th></tr>\n";
echo "<tr bgcolor="#DAD9D8" align="left"><font face="Verdana" size="2">" .$category."</font><br></tr>\n";
do {
extract( $subrow );
echo "<tr>\n";
echo "<td width="300"><font face="Verdana" size="1">$title</font><br></td>\n";
echo "<td width="120"><font face="Verdana" size="1">$time</font><br></td>\n";
echo "<td width="300"><font face="Verdana" size="1">$departments</font><br></td>\n";
echo "<td width="80"><font face="Verdana" size="1"><a href="show_positions.php?posID=$posID">view job</a></font><br></td>\n";
echo "</tr>\n";
}
while( $subrow = mysql_fetch_assoc( $subresult ) );
}
}
while( $row = mysql_fetch_assoc( $result ) );
}
else {
echo "No category available";
}
?>