FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Loop through array, change headings
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Loop through array, change headings [message #184435 is a reply to message #184432] Tue, 31 December 2013 22:06 Go to previous messageGo to previous message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma:
Senior Member
On Tue, 31 Dec 2013 21:08:42 +0000 (UTC), Adrienne Boswell wrote:

> I'm sure this has been asked and answered, but I am either too stupid to
> figure out the right way to ask Google, or I'm lazy, or it really hasn't
> been asked. Sorry in advance, and if it has been answered, please refer
> me as needed.
>
> Here's my situation:
> I have a table that has three classifications:
> id Classification
> 1 Stores
> 2 Restaurants
> 3 Services
>
> I have another table that has categories in each classification, eg.
> id Category Classification_id
> 1 Market 1
> 2 Pet Shop 1
> 3 Pizza 2
> 4 Sandwich 2
> 5 Notary 3
> 6 Repair 3
>
> My query is
> SELECT c.id, category, classification, cl.id AS classid FROM category
> c JOIN classification cl ON c.classification_id = cl.id ORDER BY classid,
> category
>
> What I want to do is:
> -Stores
> Market
> Pet Shop
> -Restaurants
> Pizza
> Sandwich
> -Services
> Notary
> Repair
>
>
> So, as I'm looping through my recordset, if the classid has changed, I
> want to change the header. I don't want to make one query to get the
> headings, and then do another query for each classid. I KNOW there has
> got to be a better way.
>
> I'm trying to get this all done so I can have a Happy New Year, and
> wishing you and yours a Happy New Year as well.

Why not have one table?
id | stores | restaurant | services

if you wanted to include actual names of
:
type | class | name
_______________________________________
stores | |
Restarants | |
Services | |

You could have as many "stores" and such as needed.
(simplified)
while (type==stores){echo 'class'; echo 'name'}
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: thank you, richard@noreply
Next Topic: PHP sql entry is a godaweful mess
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 21:53:35 GMT 2024

Total time taken to generate the page: 0.04710 seconds