How do I create a nested list inside of a while loop?

前端 未结 3 639
孤街浪徒
孤街浪徒 2021-01-21 20:29

I\'m having trouble trying to get a nested < ul > inside of a while loop. I\'m not sure if this even possible so i\'m open to alternatives.

Here\'s a quick image of w

3条回答
  •  悲哀的现实
    2021-01-21 20:51

    $result = $conn->query($sql) or die(mysqli_error());
    
    $last_category = 0;
    
    while ($row = $result->fetch_assoc()) {
    
        if($row['drinks_category_id'] != $last_category) {
            // close previous 
if( $last_category != 0 ) echo ""; // new title echo "

" . $row['drinks_category_title'] . "

"; // new
    echo "
      "; $last_category = $row['drinks_category_id']; } echo "
    • " . $row['drink_name'] . "
    • "; } // close last
    if( $last_category != 0 ) echo "
";

提交回复
热议问题