Current location: Hot Scripts Forums » Programming Languages » PHP » Using dates('w') and rows


Using dates('w') and rows

Reply
  #1 (permalink)  
Old 05-01-05, 10:57 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Using dates('w') and rows

Hi,

I'm trying to figure out the best method in order to do this system.

I wanted to have a dropdown list/menu of days (Sun - Sat). But I want to select the days available to choose from. i.e

PHP Code:



//Will be rows coming from MySql
$days $row['days'];

echo
'
<select NAME="Night" TYPE="text" class=Field STYLE="WIDTH: 190px">
<option selected>Day?</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Friday</option>
<option>Saturday</option>
</select>'

I thought the best method would be use the date('w') as it will give the days in order. I just wanted to see how you guys would do it. Quite like to use 1 filed on MySql to store the dates available to make things neater.
Reply With Quote
  #2 (permalink)  
Old 05-02-05, 03:56 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Would I be able to do it by having the var as the following

$days = 2356

maybe just take each single digit and converting into the day so

2 = Tuesday
3 = Wednesday
5 = Friday
6 = Saturday

Looping that somehow and creating the drop down menu?
So if I were to add the other days (0, 1 and 4 in this case) it will still do it.
Reply With Quote
  #3 (permalink)  
Old 05-09-05, 03:35 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
bump anyone?
Reply With Quote
  #4 (permalink)  
Old 05-09-05, 05:55 AM
harrisonad's Avatar
harrisonad harrisonad is offline
New Member
 
Join Date: May 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re

use this approach:
PHP Code:

echo "<select>";


$weekdays = array(0,'sunday','monday','tuesday','wednesday','thursday','friday','saturday');

for(
$day=1;$day<=7;$day++)
   echo 
"<option value=$day>$weekdays[week]</option>";

echo 
"</select>"
if that ain't enough, lemme know...
Reply With Quote
  #5 (permalink)  
Old 05-09-05, 10:30 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

it dont seem to work. can you tell me how to use that in order select the diffrent days from the array?

thanks
Reply With Quote
  #6 (permalink)  
Old 05-09-05, 10:58 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
ok. I had a shot the best way i know how and it kind of works except i dont know why sunday ends up at the bottom after saturday?.

Also do you know a better way to do the exact same thing. this looks like a mess.

PHP Code:

    $string '0123456';

    
$num strlen($string); 

    for(
$i=1;$i<=$num;$i++) 
    {
    
$day_of_event $string{$i};
    
$diff $day_of_event date('w');
    
$timestamp strtotime("+" $diff " days");
    
    echo 
'<option VALUE="'$timestamp .'">'date('D jS M Y'$timestamp) .'</option>';
    } 
Reply With Quote
  #7 (permalink)  
Old 05-10-05, 09:00 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
worked it out. was a silly mistake
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 06:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.