RE: [PHP] selecting current month from a database

From: Date: Mon, 22 May 2006 17:51:24 +0000
Subject: RE: [PHP] selecting current month from a database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-236654@lists.php.net to get a copy of this message
At 06:32 AM 5/22/2006, Jef Sullivan wrote:
$cur_month = date("m"); while ($r = mysql_fetch_array($month_query)) {
        $v = $r["m_id"];
      $out = $r["months"];
        if( $cur_month = $v )
        {
                echo("<option  selected=".$cur_month.
"value=".$v.">".$out."</option>")
        }
        ....
}
You're definitely saving some server machine cycles there by calculating the current month just once. On the other hand, your code would output an option only when the data month matched the current month. I'm under the impression that the original poster wanted the user to be able to select from a list of different months. Therefore I'd echo the option tag with every iteration and include the selected attribute only when the month matched. Paul

« previous php.general (#236654) next »