Jump to content

Recommended Posts

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  :shrug:

 

<?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

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))

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.