Darkwoods Posted February 15, 2010 Share Posted February 15, 2010 Hi im trying to sort my categories but i can't figure out how to do it so please i need help what im basically trying to do is to display the gategories this way: Category name -title -title Category name -Title -title i came so far with the code you can see, but i cant make it loop it just show the first category and its contents but the other categories doesn't show up <?php $result = mysql_query("SELECT * FROM cat_foodmenu ",$connect); while($row = mysql_fetch_array($result)) { $id = $row['id']; $title = $row['title']; echo '<h1>'. $title . '</h1>'; $result = mysql_query("SELECT * FROM food_menu WHERE cat_id='$title' ORDER BY id ASC",$connect); while ($row = mysql_fetch_array($result)) { $id = $row['id']; $title = $row['title']; $price = $row['price']; $info = $row['info']; echo '<div class="recipe"><span class="name_of_the_recipe">' .$title .'</span>'; echo '<div class="price">$' . $price .'</div>'; echo '<div class="recipe_bg"> </div><div class="clear_container"></div></div>'; echo '<p>(' . $info .')</p><br />'; } } ?> Link to comment https://forums.phpfreaks.com/topic/192120-how-to-sort-categories/ Share on other sites More sharing options...
MadTechie Posted February 15, 2010 Share Posted February 15, 2010 your over writing the $results, change $result = mysql_query("SELECT * FROM food_menu WHERE cat_id='$title' ORDER BY id ASC",$connect); while ($row = mysql_fetch_array($result)) to $result2 = mysql_query("SELECT * FROM food_menu WHERE cat_id='$title' ORDER BY id ASC",$connect); while ($row = mysql_fetch_array($result2)) Link to comment https://forums.phpfreaks.com/topic/192120-how-to-sort-categories/#findComment-1012502 Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 Also the other variables in the inner loop will need different names Link to comment https://forums.phpfreaks.com/topic/192120-how-to-sort-categories/#findComment-1012504 Share on other sites More sharing options...
Darkwoods Posted February 15, 2010 Author Share Posted February 15, 2010 hhaha thanks man i have been stuck with this over 4 hours thankssssss alot karma Link to comment https://forums.phpfreaks.com/topic/192120-how-to-sort-categories/#findComment-1012505 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.