jeppers Posted December 29, 2008 Share Posted December 29, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/138745-solved-can-u-help/ Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 Before I even look at your code can you put this at the end of your queries and tell me if there are any errors? $result = mysql_query($query) or die(mysql_error()); // run query Quote Link to comment https://forums.phpfreaks.com/topic/138745-solved-can-u-help/#findComment-725410 Share on other sites More sharing options...
jeppers Posted December 29, 2008 Author Share Posted December 29, 2008 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE food_id = fa.food_id AND fa.food_cat_id=1, AND fa.approved = 'Y' ORDER B' at line 2 hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/138745-solved-can-u-help/#findComment-725415 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 Try WHERE f.food_id = fa.food_id Quote Link to comment https://forums.phpfreaks.com/topic/138745-solved-can-u-help/#findComment-725417 Share on other sites More sharing options...
jeppers Posted December 29, 2008 Author Share Posted December 29, 2008 you have to be kidding, it works thanks for the quick responce. Quote Link to comment https://forums.phpfreaks.com/topic/138745-solved-can-u-help/#findComment-725421 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 Welcome. Debugging is the best tool. Please mark as solved, thx. Quote Link to comment https://forums.phpfreaks.com/topic/138745-solved-can-u-help/#findComment-725464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.