Re: [PHP] list of Months

2004-10-01 Thread Paul Bissex
On Fri, 01 Oct 2004 10:30:19 +0200, Marek Kilimajer <[EMAIL PROTECTED]> wrote:
> What about dumping the $month_names array and using strftime()?

Interesting -- more portable since the month names would then follow
locale settings.

Plus it paves the way for a really hairy one-liner. With apologies to
the original poster for the drift and the perversity of this example:

".implode("\n",array_map(create_function('$n','return"".strftime("%b",strtotime("2004-$n-01"))."";'),range(1,12)))."";
?>



-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71"W 42°19'42"N

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



Re: [PHP] list of Months

2004-10-01 Thread afan
Well, looks like the idea is alway the same, with some (very usefull)
variations.

Thanks for help!

Afan



> [EMAIL PROTECTED] wrote:
>> Hi,
>> to create a list of all months in drop-down menu I use this code:
>>
>> > $month_names = array(1=>'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
>> 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
>> ?>
>>
>> 
>> 
>> > for($i=1; $i<=12; $i++)
>> {
>>  if(date('m') == $i) $selected_QuoteMonth = 'SELECTED';
>>  else $selected_QuoteMonth = '';
>>  echo " $i ";
>> }
>> ?>
>> 
>
> What about dumping the $month_names array and using strftime()?
>

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



Re: [PHP] list of Months

2004-10-01 Thread Marek Kilimajer
[EMAIL PROTECTED] wrote:
Hi,
to create a list of all months in drop-down menu I use this code:
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
?>


 $i ";
}
?>

What about dumping the $month_names array and using strftime()?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] list of Months

2004-09-30 Thread Tom Rogers
Hi,

Friday, October 1, 2004, 6:16:46 AM, you wrote:
aan> Hi,
aan> to create a list of all months in drop-down menu I use this code:

aan>  $month_names = array(1=>'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
aan> 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
?>>

aan> 
aan> 
aan>  for($i=1; $i<=12; $i++)
aan> {
aan>  if(date('m') == $i) $selected_QuoteMonth = 'SELECTED';
aan>  else $selected_QuoteMonth = '';
aan>  echo " $i ";
aan> }
?>>
aan> 

aan> Is there any better way?

aan> Thanks for any help.

aan> Afan


Another way to skin this cat :

$month_names = array(
'Jan'=>'', 'Feb'=>'', 'Mar'=>'','Apr'=>'',
'May'=>'', 'Jun'=>'', 'Jul'=>'','Aug'=>'',
'Sep'=>'', 'Oct'=>'', 'Nov'=>'', 'Dec'=>'');
$month_names[date('M')] = ' selected';
echo '';
foreach($month_names as $month=>$selected){
echo ''.$month.'';
}
echo '';

-- 
regards,
Tom

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



Re: [PHP] list of Months

2004-09-30 Thread Paul Bissex
On Thu, 30 Sep 2004 22:16:46 +0200 (CEST), [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi,
> to create a list of all months in drop-down menu I use this code:
> 
>  $month_names = array(1=>'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
> 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
> ?>
> 
> 
> 
>  for($i=1; $i<=12; $i++)
> {
>  if(date('m') == $i) $selected_QuoteMonth = 'SELECTED';
>  else $selected_QuoteMonth = '';
>  echo " $i ";
> }
> ?>
> 
> 
> Is there any better way?

Here's how I might re-do your code (notes below):

$months = array ('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

print "";
foreach ($months as $number => $month)
{
$selected = "";
if (date ('n') == $number)
{
$selected = "selected='selected'";
}
print "$month";
}
print "";


Notes (warning, many personal biases included):

1. Quote all HTML attributes.
2. Use XHTML-compatible markup for "selected" attribute, nutty as it looks.
3. Use the month name, not the number, for your display values.
4. If you want a blank "option" entry, you might as well include it in
your array.
5. Avoid iterating through arrays with C-style "for" loops; "foreach"
is cleaner.
6. Don't continually switch between PHP and HTML modes; either write
PHP that prints HTML, or use templates.
7. Use blocks in "if" statements.
8. Use Whitesmiths brace style  :)

pb

-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71"W 42°19'42"N

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



RE: [PHP] list of Months

2004-09-30 Thread Graham Cossey
What you have is basically what I do, but the current month check could be
tidied up and display the month name seeing as you have the array:

 $selected_QuoteMonth = (date('m')==$i)?'SELECTED':'';
 echo " $month_names[$i] ";

** CODE IS UNTESTED **

I'm sure if there is a better way then someone here will let u know.

HTH

Graham

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: 30 September 2004 21:17
To: [EMAIL PROTECTED]
Subject: [PHP] list of Months


Hi,
to create a list of all months in drop-down menu I use this code:

'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
?>



 $i ";
}
?>


Is there any better way?

Thanks for any help.

Afan

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

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



Re: [PHP] list of Months

2004-09-30 Thread Pahlevanzadeh Mohsen
You can do it:
"
for ($i=1;$i<13;$i++)
  {
echo "$month[$i]";
  }
echo 
--- [EMAIL PROTECTED] wrote:

> Hi,
> to create a list of all months in drop-down menu I
> use this code:
> 
>  $month_names = array(1=>'Jan', 'Feb', 'Mar', 'Apr',
> 'May', 'Jun', 'Jul',
> 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
> ?>
> 
> 
> 
>  for($i=1; $i<=12; $i++)
> {
>  if(date('m') == $i) $selected_QuoteMonth =
> 'SELECTED';
>  else $selected_QuoteMonth = '';
>  echo " $i
> ";
> }
> ?>
> 
> 
> Is there any better way?
> 
> Thanks for any help.
> 
> Afan
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


=
-DIGITAL  SIGNATURE---
///Mohsen Pahlevanzadeh
 Network administrator  & programmer 
  My home phone is: +98213810146  
My email address is  
  m_pahlevanzadeh at yahoo dot com   
My website is: http://webnegar.net




__
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

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



[PHP] list of Months

2004-09-30 Thread afan
Hi,
to create a list of all months in drop-down menu I use this code:

'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
?>



 $i ";
}
?>


Is there any better way?

Thanks for any help.

Afan

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