RE: Re: Just can't get it to work.. variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx] 
Sent: Thursday, March 31, 2005 12:43 AM
To: php-db@xxxxxxxxxxxxx
Subject: Re:  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

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux