silphium Posted January 22, 2009 Share Posted January 22, 2009 Ok, that's an ugly subject. I don't know what else to call this. I'm doing a fairly simple app for an online business student contest. All of the contest data is in MySQL: entries, prizes categories, etc. On one page I need to display past winners for each of four prize categories. A category can have more than one winner. I first run a query to obtain the name of each prize category. No problem displaying these: foreach ($prizes as $pr) { echo '<pre>', $pr->name ,'</pre>'; } I then do a foreach loop to iterate through each category, and run a query ($projects) to find the winning entries for each category within a given year. Again, no problem -- all the queries are being run correctly. But I can't seem to retrieve and display the results of these $projects queries. If I do this: foreach ($prizes as $pr) { echo '<pre>', $pr->name ,'</pre>'; foreach($projects as $p) { echo '<pre>', $p->project_title ,'</pre>'; } } All I get is the same title for all prize categories -- from the last query. This seems like an issue of how to correctly iterate through the $projects queries and assign the results of each with the correct prize category. I used to do this sort of thing a lot when I did procedural PHP with PHP 4. But this is OOP in PHP 5, and I'm using a framework (Kohana). I know these are objects, maybe even iterator objects, and not the kinds of arrays I used to deal with. But I can't get my head around how to work with them in a situation like this. I'm sure that there's a simple answer. Can anyone prod me in the right direction? Thanks. Quote Link to comment Share on other sites More sharing options...
rubing Posted January 23, 2009 Share Posted January 23, 2009 Show us all your code. it's hard to say anything without seeing the different queries and where you put them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.