ibinod Posted June 25, 2009 Share Posted June 25, 2009 greetings, <?php $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray'); ?> <?php foreach ($author_quotes as $quote): ?> <blockquote class="">...</blockquote> <?php enforeach; ?> the $author_quotes is an array from database and it has more than 100 entry so what i am trying to do here is i want to repeat the colors from blue to gray and again blue to gray from the $colors array in <blockquote class="(here)">..</blockqutoe> i have been trying different looping method but i can't make it work, so i came over here, pls post me a quick n short soln regards Quote Link to comment https://forums.phpfreaks.com/topic/163587-solved-looping-a-loop/ Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 The syntax you have is a bit off. foreach($author_quotes as $quote) { echo '<blockquote class="">' . $quote . '</blockquote>'; //Is that where you want the quote? } Quote Link to comment https://forums.phpfreaks.com/topic/163587-solved-looping-a-loop/#findComment-863144 Share on other sites More sharing options...
ibinod Posted June 25, 2009 Author Share Posted June 25, 2009 acutally it's abit like this <?php $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray'); ?> <?php foreach($author_quotes as $quote) : ?> <blockquote class=""><?php $quote['quote'] ?></blockquote> <?php // so what i want her is i want to use the colors in the above array in place of blockquote class ?> <?php endforeach; ?> Quote Link to comment https://forums.phpfreaks.com/topic/163587-solved-looping-a-loop/#findComment-863150 Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 Not sure I quote understand. There's an array $author_quotes, you want to display all the quotes once in a different color class? Or what? Quote Link to comment https://forums.phpfreaks.com/topic/163587-solved-looping-a-loop/#findComment-863155 Share on other sites More sharing options...
Ken2k7 Posted June 25, 2009 Share Posted June 25, 2009 You mean like this - <?php $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray'); ?> <?php foreach($author_quotes as $quote) : foreach ($colors as $key => $color) : ?> <blockquote style='color: <?php echo $color; ?>;'><?php $quote['quote'] ?></blockquote> <?php // so what i want her is i want to use the colors in the above array in place of blockquote class ?> <?php endforeach; endforeach; ?> Quote Link to comment https://forums.phpfreaks.com/topic/163587-solved-looping-a-loop/#findComment-863160 Share on other sites More sharing options...
ibinod Posted June 25, 2009 Author Share Posted June 25, 2009 Not sure I quote understand. There's an array $author_quotes, you want to display all the quotes once in a different color class? Or what? Let's assume i have 100 different quotes to get from my database and i have seven different styles so i want to display those 0 to 100 quotes from (0- blue to 6- gray again 7-blue to 13-gray) like this You mean like this - <?php $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray'); ?> <?php foreach($author_quotes as $quote) : foreach ($colors as $key => $color) : ?> <blockquote style='color: <?php echo $color; ?>;'><?php $quote['quote'] ?></blockquote> <?php // so what i want her is i want to use the colors in the above array in place of blockquote class ?> <?php endforeach; endforeach; ?> Yes, somewhat like that, i tried that previously also but what happens there is it repeats each quote 7 time so i don't want it to repeat the quotes, just the colors from blue to gray Quote Link to comment https://forums.phpfreaks.com/topic/163587-solved-looping-a-loop/#findComment-863162 Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 You can try something different like this: <?php $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray'); for($i = 0;$i < count($author_quotes);$i++) { $color = $colors[$i%7]; echo '<blockquote class="' . $color . '">' . $author_quotes[$i] . '</blockquote>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163587-solved-looping-a-loop/#findComment-863168 Share on other sites More sharing options...
ibinod Posted June 25, 2009 Author Share Posted June 25, 2009 You can try something different like this: <?php $colors = array('blue', 'red', 'green', 'purple', 'orange', 'brown', 'gray'); for($i = 0;$i < count($author_quotes);$i++) { $color = $colors[$i%7]; echo '<blockquote class="' . $color . '">' . $author_quotes[$i] . '</blockquote>'; } ?> Thanx alot mate, that worked as i wanted. Regards Quote Link to comment https://forums.phpfreaks.com/topic/163587-solved-looping-a-loop/#findComment-863180 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.