elliotpo Posted January 23, 2010 Share Posted January 23, 2010 Hello, I can't find anything about this subject here... if I missed a relevant post, I apologize. I'm pulling search results from two MySQL tables. I then need to parse the results into a foreach loop that's also outputting DIVs Javascript-controlled DIVs. The searches are like so. find_by_sql generates an object array that aligns db table fields as values with class attributes as keys. <?php $sql = "SELECT * FROM artists ORDER BY number ASC"; $musicians = artists::find_by_sql($sql); $sql = "SELECT * FROM artistPics ORDER BY number ASC"; $mpics = artistPics::find_by_sql($sql); ?> Then the output: <div id="musicians"> <p>Musician Profiles - click to learn more</p> <div id='Accordion1' class='Accordion' tabindex='0'> <?php foreach($musicians as $m) { echo "<div class='AccordionPanel'>"; echo "<div class='AccordionPanelTab'>$m->artist_name - $m->artist_role</div>"; echo "<div class='AccordionPanelContent'><img src='' />$m->artist_bio</div>"; echo "</div>"; } ?> </div> I need to get the picture output into the img src spot. But running a foreach loop inside another screws up everything, and I can't figure any other way. I could do the processing up top and try to parse out the pics into variables I'd then just call below, but there are an indeterminate number of artists in the table at any time, and I can't figure of that's possible without knowing how many results would have to be parsed. I hope this makes some sense-- I'd appreciate any advice. Thanks so much - elliotpo Quote Link to comment https://forums.phpfreaks.com/topic/189570-parsing-arrays-generated-from-distinct-mysql-tables-into-one-foreach-loop/ Share on other sites More sharing options...
teamatomic Posted January 24, 2010 Share Posted January 24, 2010 For the artist_pic_array make it so: key=artist name // same as the artist name pulled from the other table value=artists pic location so in your example the artist name is $m artist_pic_array[$m] would give you the pics location HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189570-parsing-arrays-generated-from-distinct-mysql-tables-into-one-foreach-loop/#findComment-1000620 Share on other sites More sharing options...
elliotpo Posted January 24, 2010 Author Share Posted January 24, 2010 Ah, I appreciate the feedback-- but the trouble is that the foreach output has to repeat X number of times. and the pic changes each time. so i'm not sure how to call items from a second array (the pics array) while the first array (the artists array) is outputting. the DIVS wind up repeating multiple times and the whole thing jumbles. the $m that's holding artist data just comes from the foreach loop instructions... Unless I'm misunderstanding your advice? Which is possible.. Quote Link to comment https://forums.phpfreaks.com/topic/189570-parsing-arrays-generated-from-distinct-mysql-tables-into-one-foreach-loop/#findComment-1000939 Share on other sites More sharing options...
elliotpo Posted January 25, 2010 Author Share Posted January 25, 2010 Ah. Nevermind. Your advice was good. I didn't know how to query multiple MySQL tables at once. Quote Link to comment https://forums.phpfreaks.com/topic/189570-parsing-arrays-generated-from-distinct-mysql-tables-into-one-foreach-loop/#findComment-1001493 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.