Current location: Hot Scripts Forums » Programming Languages » PHP » Which way to display results from mysql


Which way to display results from mysql

Reply
  #1 (permalink)  
Old 09-12-03, 07:48 AM
Peter_web Peter_web is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Which way to display results from mysql

I have many-to-many relationship database. In one table i have listed all genres
Code:
id | genre
1 | pop
2 | techno
...
In sencond table I have listed albums...
Code:
id | album
7 | Come on
8 | No world
...
those two tables are glued with third table...
Code:
id_genre | id_album
1             | 7
2             | 7
1             | 8
hrere is my question.... When I select albums and related genres I get duplicated rows (which is ok - i think). how do I display results? What are the coding standards?

Results
Code:
1. Come on - pop
2. Come on - techno
3. No world - pop
I would need results output something like this...
Code:
1. Come on Genres: pop, techno
2. No world Genres: pop
What are the ways to get such output? (making array...) How would I get records count (without duplicates)?
Reply With Quote
  #2 (permalink)  
Old 09-12-03, 09:31 AM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
What are the ways to get such output? (making array...) How would I get records count (without duplicates)?
The easiest way would be to have two queries. One to get all albums and then the other would get all the genre's that the album occurs in. You could also drop the results in a multi-dimensional array like:

$a[album][genre]

or just output them with a while loop.

Does that help ?
Reply With Quote
  #3 (permalink)  
Old 09-13-03, 05:39 PM
Peter_web Peter_web is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
So, then this is an efficient way to display the results (put results in an array) since we avoid creating recursive sql queries?

like this one...
Code:
select * from albums where ....

while rows {
  print album info

 select * from genres....
    while{
     print genres
    }

}
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
If date is less than today do not display jimthepict ASP 5 10-19-03 10:43 PM
Forum/Board - MySQL = Possible? cipher PHP 7 10-07-03 03:42 AM
great product for dumping/recovering MySQL databases Dave Brown General Advertisements 1 10-03-03 07:40 AM
mysql to access aspuser25 Database 2 09-16-03 11:01 AM


All times are GMT -5. The time now is 07:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.