Jump to content


Photo

array


  • Please log in to reply
3 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 11 August 2006 - 08:09 PM

i need to populate a select box with the days of the week, starting from today and finishing with the day before today, i.e.

friday. sat. sun. mon. tue. wed. thursday.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,020 posts

Posted 11 August 2006 - 08:25 PM

Try
<?php
$today = mktime(0,0,0);

echo '<select name="day">';
for ($i=0; $i<7; $i++) {
	$val = date('l', strtotime("+$i days", $today));
	echo "<option value='$val'>$val</option>";
}
echo '</select>';
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 11 August 2006 - 08:33 PM

My version  ;)

<?php
$now=time();
$day_seconds=60*60*24;
echo('<select name="day">');
$count=0;
while($count<=6){
$timestamp=$now+($count*$day_seconds);
$day=date("l",$timestamp);
echo('<option name="'.$day.'">'.$day);
$count++;
}
echo '</select>';
?>

I tested it and it works :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#4 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 15 August 2006 - 06:19 PM

thanks both of u...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users