Jump to content

[SOLVED] can u help


jeppers

Recommended Posts

i am working on a query. which should pull infomation from a database and sort it by the category chosen. i am have not worked with querys for long. so i am a little baffled.. can you help

 

//this will create the pull down box for the query
echo '<div align="center"> <form method="get" action="posible.php">
<select name="type">
<option value="NULL">Choose your food:</option>';

//retreve and desplay food cat 
$query = 'SELECT * FROM food_categories ORDER BY category ASC';
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
	echo "<option value=\"$row[0]\">$row[1]</option>";
}

//complete the form 
echo '</select>
<input type="submit" name="submit" value="GO">
</div>';

// retrive the food for a particular category 
// and make sure the type is an interger 
if (isset($_GET['type'])) {
$type = (int)$_GET['type'];
} else {
$type = 0;
}

if ($type > 0) {

//get the current type 
$query = "SELECT category  FROM food_categories WHERE food_cat_id=$type";
$result = mysql_query($query);
list ($category) = mysql_fetch_array($result, MYSQL_NUM);

$first =  TRUE; // initialize the variable

//query the database
$query = "SELECT f.food_id, food, title, description, price FROM foods AS f,
food_associations AS fa, WHERE food_id = fa.food_id AND fa.food_cat_id=$type,
AND fa.approved = 'Y' ORDER BY date_submitted ASC";

$result = mysql_query($query); // run query

//display all the urls.
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {

 

its the last query which is causing the problems so what do u think. hope someone will help

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/138745-solved-can-u-help/
Share on other sites

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.