Displaying headings

M

maxvalery

Hi,

I got about 50 meal names in a table, each meal has a category. I need
to loop thought the meals in such a way that the category name is
displayed at the top of each group. For instance,

I need:

Categ. Name 1
Meal 1
Meal 2
Meal 3

Categ. Name 2
Meal 4
Meal 5
Meal 6

I can do:

Categ. Name 1
Meal 1
Categ. Name 1
Meal 2
Categ. Name 1
Meal 3
Categ. Name 1
Meal 4

My code:

sql_string = "SELECT newmenu_name, newmenu_price, newmenu_desc,
cat_desc, cat_tagline FROM newmenu_meals, newmenu_categories WHERE
cat_name=newmenu_cat;"
rs.Open sql_string, conn

Do Until rs.EOF
response.write("<b>" & rs("newmenu_name") & "</b><br />")
response.write("<em>" & FormatCurrency(rs("newmenu_price")) &
"</em><br />")
response.write(rs("newmenu_desc") & "<br /><br /><br />")
rs.movenext
Loop

How to I move the category name outside of the rs loop?

Thanks!
 
C

Cindy M -WordMVP-

I got about 50 meal names in a table, each meal has a category. I need
to loop thought the meals in such a way that the category name is
displayed at the top of each group. For instance,

I need:

Categ. Name 1
Meal 1
Meal 2
Meal 3

Categ. Name 2
Meal 4
Meal 5
Meal 6

I can do:

Categ. Name 1
Meal 1
Categ. Name 1
Meal 2
Categ. Name 1
Meal 3
Categ. Name 1
Meal 4

My code:

sql_string = "SELECT newmenu_name, newmenu_price, newmenu_desc,
cat_desc, cat_tagline FROM newmenu_meals, newmenu_categories WHERE
cat_name=newmenu_cat;"
rs.Open sql_string, conn

Do Until rs.EOF
response.write("<b>" & rs("newmenu_name") & "</b><br />")
response.write("<em>" & FormatCurrency(rs("newmenu_price")) &
"</em><br />")
response.write(rs("newmenu_desc") & "<br /><br /><br />")
rs.movenext
Loop

How to I move the category name outside of the rs loop?
Use a variable to store the category name. Assign the category name to
the variable at the end of the loop and check it against the category of
the record that follows at the top of the loop (if sCat =
rs("newmenu_categories")) If they match, leave it out of the response in
this loop and process only the other fields. If they don't match, the
category has changed and you need to include it in the response.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top