Jump to content

narrowing sql SELECT using a number of variables


PHP_ie

Recommended Posts

can anyone offer advice on this?

 

I want to be able to limit what is selected for the database with a number of drop down menus, but can't get it working.

<?php 

include("test_sbumit.php");
echo"<br>";
echo"<br>";

printf("Your current category is: %s", $_SERVER['QUERY_STRING']); 


echo"<br>";
echo"<br>";

$category = $_SERVER['QUERY_STRING'];


$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("alpha", $con);

echo "<form action='showproducts.php' method='POST'>";

echo "<table border='1'>";
echo "<tr>";
echo "<td>";
echo "<a>price: €</a>";
echo "<select name='price'>";
echo "<option value='all'>All</option>";
echo "<option value='499'>0 - 499</option>";
echo "<option value='999'>500 - 999</option>";
echo "<option value='1499'>1000 - 1499</option>";
echo "<option value='1999'>1500 - 1999</option>";
echo "<option value='2000'>2000 +</option>";
echo "</td>";
echo "<td></td>";
echo "<td><input type='submit' value='go'></td>";
echo "</tr>";
echo "</table>";


If ($price != "All"){
$result = mysql_query("SELECT prodID, title, price FROM product WHERE category='$category' AND price<'$price'");

while($row = mysql_fetch_array($result))
  {
   	printf("<a href='showone.php?%s'>%s</a> %s <br> ",$row['prodID'],$row['title'],$row['price']);

  }
}

mysql_close($con);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.