luminous Posted May 5, 2010 Share Posted May 5, 2010 I have an array of months: $titleMonths = array ( 0=> 'January', 1=> 'Febuary', 2=> 'March', 3=> 'April', 4=> 'May', 5=> 'June', 6=> 'July', 7=> 'August', 8=> 'Septmeber', 9=> 'October', 10=> 'November', 11=> 'Decem' ); I also have a list of values stored in a database, the month value for these values is stored as a $items['month'] which is an integer e.g 5 (for May) I'm trying to run a foreach loop that goes through the list of months, if the array position is the same as the month number, it'll echo the title for the month with all the values for that month underneath it. So far experimenting I've managed to echo just the $titleMonth values, echo the $titleMonth values for as many results as the database returns, but so far no donut! Here's what I've been working with ($dates is the rows returned from the database) $titleMonths = array ( 0=> 'January', 1=> 'Febuary', 2=> 'March', 3=> 'April', 4=> 'May', 5=> 'June', 6=> 'July', 7=> 'August', 8=> 'Septmeber', 9=> 'October', 10=> 'November', 11=> 'Decem' ); foreach($titleMonths as $month) { echo $this->_html .= $month; for($i = 0; $i < count($titleMonths); $i++) { foreach ($dates as $items) { echo $items['day'].'/'.$items['month'].'/'.$items['year'] } } } Please help in anyway you can! Quote Link to comment https://forums.phpfreaks.com/topic/200769-foreach-echo-titles-for-content/ Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 It's probably just me, but your objective here is unclear. What are these "values underneath" that you are reffering to, where are they stored, what does your select statement look like? Where does the information form the database come into the script? Quote Link to comment https://forums.phpfreaks.com/topic/200769-foreach-echo-titles-for-content/#findComment-1053481 Share on other sites More sharing options...
MadTechie Posted May 5, 2010 Share Posted May 5, 2010 I am not sure what you mean, but you could just use date to format the result, but if you wanted to use the array why not just do this echo $titleMonths[$items['month']-1] or $titleMonths = array ( 1=> 'January', 2=> 'Febuary', 3=> 'March', 4=> 'April', 5=> 'May', 6=> 'June', 7=> 'July', 8=> 'August', 9=> 'Septmeber', 10=> 'October', 11=> 'November', 12=> 'Decem' ); echo $titleMonths[$items['month']] Quote Link to comment https://forums.phpfreaks.com/topic/200769-foreach-echo-titles-for-content/#findComment-1053482 Share on other sites More sharing options...
luminous Posted May 5, 2010 Author Share Posted May 5, 2010 Hi, I just re-read this and I made it pretty unclear I want to achive, but this is it basically; Each time there is value in the $datas array, I want to match it against the $titleMonths array and to echo the values of data under the titleMonths value e.g ($items['month'] = 1) January 07/01/2010 29/01/2010 ($items['month'] = 4) April 03/04/2010 13/04/2010 Quote Link to comment https://forums.phpfreaks.com/topic/200769-foreach-echo-titles-for-content/#findComment-1053494 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 I see, so this is just about your arrays, nothing at all to do with a database then? Quote Link to comment https://forums.phpfreaks.com/topic/200769-foreach-echo-titles-for-content/#findComment-1053512 Share on other sites More sharing options...
luminous Posted May 5, 2010 Author Share Posted May 5, 2010 nope, I'm getting the data just fine and the arrays have what I want stored in them, it's just a case of extracting the data and presenting it in this way! Quote Link to comment https://forums.phpfreaks.com/topic/200769-foreach-echo-titles-for-content/#findComment-1053517 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 I see, I thought that you were storing all the information in a database, then pulling it out for your page, that I could have helped with. I'll have to concede I don't know a whole lot about array manipulation with PHP yet so can't offer any help with that Quote Link to comment https://forums.phpfreaks.com/topic/200769-foreach-echo-titles-for-content/#findComment-1053519 Share on other sites More sharing options...
teamatomic Posted May 5, 2010 Share Posted May 5, 2010 The first thing you need to do is to sort the dates array so the dates(months) are in order and grouped. array_multisort would work fine for that. Once the array is in ascending groups it should not be too hard to get them under the proper month. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/200769-foreach-echo-titles-for-content/#findComment-1053526 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.