Re: Re: Just can't get it to work.. variables
| From: | Martin Norland | Date: | Wed, 30 Mar 2005 14:43:15 +0000 |
| Subject: | Re: Re: Just can't get it to work.. variables | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-39070@lists.php.net to get a copy of this message | ||
David Robley wrote:
Gavin Amm wrote: [snip]
That would indicate that you are actually saying: $monthVal = $monthName[04]; where the 04 is actually a string; you have no element '04' in your array. Cast $monthInt to an integer before you use it as an array element. Alternatively, if you are using MySQL, you can use DATE_FORMAT to achieve the same result.Yep, also - no need to redeclare $monthName each iteration. If you wanted you could also just declare it thusly: $monthName = array ("01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr", "05" => "May", "06" => "Jun", "07" => "Jul", "08" => "Aug", "09" => "Sep", "10" => "Oct", "11" => "Nov", "12" => "Dec"); ... incidentally, Oct/Nov/Dec should have worked previously afaik, PHP is fairly forgiving. You can probably also get away with just using round() to get your integers where you need them, instead of the declaration above. cheers, -- - Martin Norland, Sys Admin / Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital.### ORIGINAL CODE ### while ($row = mysql_fetch_array($result)){ $monthName = array ("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); echo "<p><b>".$monthName[substr($row['start'], 4, 2)]." ".substr($row['start'], 6, 2)."</b><br>\n".$row['details']."\n</p>\n\n"; }