Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6938613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:30:55+00:00 2026-05-27T12:30:55+00:00

I have a mysql table |————|———–|————| | Catagory | Item | Price | |————|———–|————|

  • 0

I have a mysql table

|------------|-----------|------------|
|  Catagory  |    Item   |   Price    |
|------------|-----------|------------|
|    Soup    | Split Pea |  $1.99     |
|    Soup    | Onion     |  $2.99     |
| MainCourse | Steak     |  $9.99     |
| MainCourse | Shrimp    |  $11.99    |
|-------------------------------------|

I am looking to end up with html unordered list

 Soup<br>
       <ul>
            <li class="menuItem">Split Pea - $1.99</li>
            <li class="menuItem">Onion - $2.99</li>
       </ul>

  MainCourse<br>
       <ul>
            <li class="menuItem">Steak - $9.99</li>
            <li class="menuItem">Shrimp -$11.99</li>
       </ul>

This is my php

 <?php $testvalue='1' ?>
 <?php do { ?>
 <?php if ($testvalue!=$row_rs_items['category']) { echo $row_rs_items['category']; echo "<br>","<ul>"; } ?> 
  <li class="menuItem"><?php echo $row_rs_items['name']; ?> - <?php echo $row_rs_items['price']; ?></li>
  <?php $testvalue=$row_rs_items['category']; ?>    
  <?php } while ($row_rs_items = mysql_fetch_assoc($rs_items)); ?>

The code works to create opening <UL> on the first entry for catagory. However I am looking for a way to add a </UL> when the next row is of a new catagory. Is there a way to peak in to the next row when interating over the recordset?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:30:56+00:00Added an answer on May 27, 2026 at 12:30 pm

    Try this,

    $row_rs_items = mysql_fetch_assoc($rs_items);
    if($row_as_items)
     {
      $prevCategory=$row_rs_items['category'];
      $currCategory=$prevCategory;
      echo "<ul>";
      do
       {
          if($prevCategory!=$currCategory)
           {
              echo "</ul><ul>";
              $prevCategory=$currCategory;
            }
          echo "<li class='menuItem'>$row_rs_items[name]</li>";
          $row_rs_items = mysql_fetch_assoc($rs_items)
          if($row_rs_items)
              $currCategory=$row_rs_items['category'];
       }while($row_rs_items);
        echo "</ul>";
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql table that has a column that stores xml as a string.
I have MySQL InnoDB table utf-8 encoded. This table has only id and name
I have a MySQL table and would like to return the rows based on
I have a MySql table containing stock quotes (stock_symbol, quote_date, open_price, high_price, low_price, close_price)
I have a MySQL table that looks something like this: +-----+------------+ | id |
I have a MySQL table like so; foo bar 1 21 23 17 31
I have a MySQL table called accounts . Within this table is a field
I have a MySQL table with an auto-incremented integer primary key. I want to
I have a mysql table structure like that: id int primary key name varchar
I have a MySQL table, in which I will be storing the email_id of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.