|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Problem sorting/grouping/displaying MySQL data
Hi everybody,
I have a rather (hopefully ) simple question, but I can't figure this out even though I've worked on it way over an hour.I'm pretty good at PHP and MySQL (by the way the data is ok), but like I said I just can't figure this out. I've tried for's,while's, and other things but no luck. We have a newsletter table. Each issue of the newsletter has 1 or more tips, and each tip is stored in a separate row. Here's the sample table: id,newsletter_id,title,content ----------------------------------------------------- 1,1,item 1,tip1 2,1,item 2,tip2 3,2,item 1,tip1 4,3,item 1,tip1 5,3,item 2,tip2 6,3,item 3,tip3 7,3,item 4,tip4 .......... ----------------------------------------------------- I would like to display the page like this: Newsletter 1 --item 1 --item 2 Newsletter 2 --item 1 Newsletter 3 --item 1 --item 2 --item 3 --item 4 .......... Sample code: PHP Code:
Can I please get some help?!?! I'm about to go crazy! Thanks a lot! |
|
#2
|
|||
|
|||
|
Well, a couple of tips. Hope they help.
Tip 1: Why don't you store the data in two tables?Tip 2: If you're intent on using one table try this.Let me know how you make out. |
|
#3
|
|||
|
|||
|
tobycloud,
I tried to use your grouping code listed above but cannot seem to get it to work without parse errors. I modified it a littel to match what we need. Please take a look and tell me what I am missing. PHP Code:
Thank you ahead of time. G |
|
#4
|
|||
|
|||
|
Here's the updated code I use.
Not very efficient but it works. Table "tips": id,newsletter_id,title,content Each newsletter tip is stored in the tips table. There's a "newsletter_id" field because not all the tips in the table are newsletters. Confusing? Yes - but here's the finished product (similar not exact code): http://www.acctadv.com/newsletters.php PHP Code:
Basically, the total number of newsletters are retrieved, then a reverse "for" loop gets the specific newsletter and prints it out. |
|
#5
|
|||
|
|||
|
Hi. I am pondering, why not just use the "group by" function in the mysql_query(); ??
- Pheifel |
|
#6
|
|||
|
|||
|
Pheifel,
I was doing some reading and wondered the same thing, but I am just a novice at php. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Problem sorting/grouping/displaying MySQL data |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|