Re: Date Formatting Question

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

 



Apart from anything, you need to supply an option value for each of those options, not just rely on the browser which will default to passing the option *text* back from the form, if you specify no value. So your option elements should read

<option value="1">January</option>

Notwithstanding that, RE below - you guys are all nuts, this is a ridiculous way to do it.
Let MySQL do the work, it has perfectly good functions to do this :

SELECT  DATE_FORMAT(date_field_name, '%c') AS intDate,
                DATE_FORMAT(date_field_name, '%M'') AS strMonth
FROM yadda etc etc

Then you use (assuming your're using $result = mysql_fetch_assoc() as your looped result variable name)

$optionlist='';
$selected_month = (integer) $_GET["Smonth"];

while ($result = mysql_fetch_assoc($link)) {
        $optionlist.="<option";
        if ($selected_month==$result['intDate']) {
                $optionlist.=' selected="selected"';
        }
        $optionlist.='"'.$result['intDate'].'">'.$result['strMonth']."</option>'\r\n\t";
}       //      End while

print($optionlist);

HTH
Cheers, Neil



To: php-db@xxxxxxxxxxxxx
Date: Wed, 14 Dec 2005 15:52:31 +0100
From: El Bekko <elbekko@xxxxxxxxx>
Reply-To: elbekko@xxxxxxxxx
Subject: Re: Date Formatting Question

Bomgardner, Mark A wrote:
I am trying to format the month portion of a date that I am trying to
pull from MySQL to be placed into a drop down menu to modify the date.
...snip...
modify and it would be easier to do it in PHP
Any pointers would be appreciated.

Mark Bomgardner
Technology Specialist
KLETC

make a function like this:

function datenum2str($date)
        {
        $newdate = str_replace("01","Jan",$date);
        $newdate = str_replace("02","Feb",$date);
        $newdate = str_replace("03","Mar",$date);
        $newdate = str_replace("04","Apr",$date);
        $newdate = str_replace("05","May",$date);
        $newdate = str_replace("06","Jun",$date);
        $newdate = str_replace("07","Jul",$date);
        $newdate = str_replace("08","Aug",$date);
        $newdate = str_replace("09","Sep",$date);
        $newdate = str_replace("10","Oct",$date);
        $newdate = str_replace("11","Nov",$date);
        $newdate = str_replace("12","Dec",$date);

        return $newdate;
        }

And then use this:

echo "<select name=Smonth>";
echo "<option selected value=\"$sDate[1]\">$newdate</option>";


Hope it helps,

El Bekko



========================================================
CaptionKit http://www.captionkit.com : Production tools
for accessible subtitled internet media, transcripts
and searchable video. Supports Real Player, Quicktime
and Windows Media Player.

VideoChat with friends online, get Freshly Toasted every
day at http://www.fresh-toast.net : NetMeeting solutions
for a connected world.

--
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