Computing.Net > Forums > Web Development > Display 1 heading then many results

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Display 1 heading then many results

Reply to Message Icon

Name: martineagle
Date: March 1, 2007 at 21:35:55 Pacific
OS: Win XP Pro
CPU/Ram: Pentuim M 1.8 / 512
Product: HP
Comment:

I have a table in mysql, each item has a heading, a title, and a description. Some entries have the same heading but always a different title and description. I'd like to display it dynamically in a page like this:


HEADING
-------------
TITLE >> DESCRIPTION
TITLE >> DESCRIPTION
TITLE >> DESCRIPTION
-------------


HEADING
-------------
TITLE >> DESCRIPTION
TITLE >> DESCRIPTION
TITLE >> DESCRIPTION
-------------

and so on...


What I'd like assistance with is learning how to display the heading once and then display all the results (titles and descriptions) that match the same heading, then repeat this process for each of the other items that match the other headings.

Can anyone help? I know it's probably basic to many but I can figure it out and am having trouble finding assistance on the web that suits my needs.

Thanks in advance,
Martin




Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: March 2, 2007 at 12:36:23 Pacific
Reply:

What language are you using?

Michael J


0

Response Number 2
Name: martineagle
Date: March 2, 2007 at 20:34:06 Pacific
Reply:

Language is php/MySQL.

I've since found this solution but if you have a better idea I'd be happy to hear about it.


$result = mysql_query("SELECT * FROM tablename ORDER BY heading");
$check = '';
while($r=mysql_fetch_object($result)){
if($check != $r->heading){
echo "

$r->heading</p>";
$check = $r->heading;
}
echo "$r->title >> $r->description<br />";
}
?>


0

Response Number 3
Name: Michael J (by mjdamato)
Date: March 3, 2007 at 09:55:52 Pacific
Reply:

That's exacly what I would have done.

Michael J


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Dynamically Creating Hype... Finding broken links



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Display 1 heading then many results

ONE Password Point - MANY Results?? www.computing.net/answers/webdevel/one-password-point-many-results/91.html

can't edit or add records - asp.net www.computing.net/answers/webdevel/cant-edit-or-add-records-aspnet/109.html

Problem with CGI script- pls help!! www.computing.net/answers/webdevel/problem-with-cgi-script-pls-help/198.html