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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.