RE: [PHP-DB] Re: Just can't get it to work.. variables
| From: | Gavin Amm | Date: | Thu, 31 Mar 2005 01:18:14 +0000 |
| Subject: | RE: [PHP-DB] Re: Just can't get it to work.. variables | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-39078@lists.php.net to get a copy of this message | ||
Yeah, I ended up doing that (associative array) then reading your
e-mail.. Oh well, thanks.
I couldn't cast the var as an int. in the database it's setup as a
timestamp(8) (yyyymmdd), not sure why I set it up as such..
Cheers,
Gavin
-----Original Message-----
From: Martin Norland [mailto:martin.norland@stjude.org]
Sent: Thursday, March 31, 2005 12:43 AM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] Re: Just can't get it to work.. variables
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.
>
>>### 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";
>>}
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.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php