Current location: Hot Scripts Forums » Programming Languages » PHP » Loop - Convert number into day of the week

Loop - Convert number into day of the week

Reply
  #1 (permalink)  
Old
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Loop - Convert number into day of the week

I have this following Loop.

PHP Code:

// Loop Start while 

while ($night=mysql_fetch_assoc($result)) { 
echo
'<TABLE width="590" height="12" border=0 cellPadding=0 cellSpacing=0 bordercolor="#CCCCCC"> 
     <TBODY> 
     <TR> 
     <TD width="200" height="12" class="mainText">'
$night['name'] .' - '$night['iddays'] .'</TD> 
     </TR> 
     </TBODY> 
     </TABLE>'

// Loop End 

'. $night['iddays'] .' results as a numerical number. 0, 1 , 2 , 3, 4 etc up to 6. Each number representing a day of the week. 0 = Sunday, 1 = Monday, 2= Tuesday etc 6 = Saturday.

The script below only shows the numerical result. How can I convert the numbers so it will show the day of the week.
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
NeverMind's Avatar
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
PHP Code:

$days[0] = 'Sat';

$daye[1] = 'Sun';
$days[2] = 'Mon';
$days[3] = 'Tue';
$days[4] = 'Wed';
$days[5] = 'Thu';
$days[6] = 'Fri';

// Loop Start while
while ($night=mysql_fetch_assoc($result)) {
echo
'<TABLE width="590" height="12" border=0 cellPadding=0 cellSpacing=0 bordercolor="#CCCCCC">
     <TBODY>
     <TR>
     <TD width="200" height="12" class="mainText">'
$night['name'] .' - '$days[$night['iddays']] .'</TD>
     </TR>
     </TBODY>
     </TABLE>'
;
// Loop End

enjoy
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Man, it seems so obvious when you see it. Thanks again NM
Reply With Quote
  #4 (permalink)  
Old
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
another little question on this: How could I get the dates of that day for a selected month. i.e

if 0 = Sun then how can I get all the Sundays of a selected month

The script below is a attempt from another system i had. I'm sure its complety worng but i also want to know how you can loop within a loop. never done that before... I think this is not too far off either...

PHP Code:



// Select Date Script
$day_of_event $night['iddays']; // assuming friday in this example 
$num_weeks 4// how many weeks ahead to show 

$diff $day_of_event date("w"); 
$timestamp strtotime("+" $diff " days"); 

// Loop Start while 
while ($night=mysql_fetch_assoc($result)) {
echo
'
<TABLE width="590" height="12" border=0 cellPadding=1 cellSpacing=1 bordercolor="#CCCCCC">
<TBODY>
<TR> 
<TD width="200" height="12" class="mainText">'
$night['name'] .' | '$days[$night['iddays']] .'</TD>
<TD width="54" class="mainText">0</TD>
<TD width="64" class="mainText">0</TD>
<TD width="58" class="mainText">
<img src="xls.gif" width="16" height="16"> 
<img src="pdf.gif" width="16" height="16"><a href="http://www.selectguestlist.com/guestlist/list.php?day=26&month=6&night=1"><img src="html.gif" width="16" height="16" border="0"></a></TD>
<TD width="122" class="mainText"> 
<select name="select" class="mainFormBox" style="WIDTH: 120px">'
;

for(
$i=1;$i<$num_weeks;$i++) 

   
$timestamp strtotime('+1 week'$timestamp); 
   echo 
'<option value="' $timestamp '">' date('l d F Y'$timestamp) . '</option>'
}

echo
'</select>
</TD>
</TR>
</TBODY>
</TABLE>'

// Loop End 

What I'm trying to do:
http://www.selectguestlist.com/guest...?=feneo&club=1

Last edited by dihan; 06-27-04 at 06:05 PM.
Reply With Quote
  #5 (permalink)  
Old
NeverMind's Avatar
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
I think that you don't need this part:
PHP Code:

// Select Date Script

$day_of_event $night['iddays']; // assuming friday in this example
$num_weeks 4// how many weeks ahead to show

$diff $day_of_event date("w");
$timestamp strtotime("+" $diff " days"); 
unless there is another use of it in the rest of script..
all you need is $num_weeks..
you need before the for() loop something like that:
PHP Code:

$timestamp time();


for(
$i=1;$i<$num_weeks;$i++)
{
   
$timestamp strtotime('+1 week'$timestamp);
   echo 
'<option value="' $timestamp '">' date('l d F Y'$timestamp) . '</option>';

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #6 (permalink)  
Old
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
strangly it did not return anything. Have I done the "for" bit correct? Is that how you can do a loop within a loop?

PHP Code:

<TD width="122" class="mainText"

<
select name="select" class="mainFormBox" style="WIDTH: 120px">
</
select>

</
TD
Reply With Quote
  #7 (permalink)  
Old
New Member
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
In response to NeverMind:

You dont have to declare days[] over and over like that.

You can just simply do the following:

PHP Code:

$days = array("Sat""Sun""Mon""Tue""Wed""Thu""Fri"); 

Not required, but just some advice to speed things up just a bit.
Reply With Quote
  #8 (permalink)  
Old
NeverMind's Avatar
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Originally Posted by Rylas
In response to NeverMind:

You dont have to declare days[] over and over like that.

You can just simply do the following:

PHP Code:

$days = array("Sat""Sun""Mon""Tue""Wed""Thu""Fri"); 

Not required, but just some advice to speed things up just a bit.
yes I know ,,
but I prefer the first method for its clearity!

as for dihan, could you put the code after you changed it ?
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #9 (permalink)  
Old
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
sure de do da... :-) I know I pasted allot of it but I wated to show how I get months up... Which will determin which 4 days of the month that it should show. - [$night['iddays'] will show what day to look for and name="month" will give a number 1-12 of what month to look for and will populate name="select" with selected days of that month. (This is my main problem)

http://www.selectguestlist.com/guest...eo[DELETE]

Hope that makes sence.

PS This new forum template is looking slick...


PHP Code:

//NM's date conversion

$days[0] = 'Sunday'
$days[1] = 'Monday'
$days[2] = 'Tuesday'
$days[3] = 'Wednesday'
$days[4] = 'Thursday'
$days[5] = 'Friday'
$days[6] = 'Saturday'

$timestamp time(); 

echo
'
<body bgcolor="#155271" text="#FFFFFF" link="#CCCCCC" vlink="#666666" alink="#CCCCCC">
<TABLE width="408" border=0 align="center" cellPadding=0 cellSpacing=0>
<TBODY>
<TR> 
<TD><img src="http://www.selectguestlist.com/logos/mojo.jpg" width="600" height="57" border="0"></TD>
</TR>
<TR> 
<TD height="10"></TD>
</TR>
</TBODY>
</TABLE>
<TABLE width="600" border=0 align="center" cellPadding=0 cellSpacing=0>
<TBODY>
<TR></TR>
<TR> 
<TD width="600" vAlign=top> 
      
      
<TABLE width="100%" height="77" border=0 cellPadding=0 cellSpacing=0>
<TBODY>
<TR> 
<TD width=6><IMG height=8 alt="" src="http://www.selectguestlist.com/index/home/bdr_leftcr.gif" width=6 border=0></TD>
<TD height=6 colspan="3" background=http://www.selectguestlist.com/index/home/bdr_top.gif></TD>
<TD width=6><IMG height=8 alt="" src="http://www.selectguestlist.com/index/home/bdr_rightcr.gif" width=6 border=0></TD>
</TR>
<TR> 
<TD width=6 background="http://www.selectguestlist.com/index/home/bdr_leftside.gif"></TD>
<TD width="61" colspan="3" bgColor=#0F364A class="mainText"><TABLE width="590" height="12" border=0 cellPadding=0 cellSpacing=0 bordercolor="#CCCCCC">
<TBODY>
<TR> 
<TD width="350" height="12" class="mainText"></TD>
<TD width="240" class="mainText"><form name="form1">
<div align="right">
<select name="month" class="mainFormBox" style="WIDTH: 240px" onChange="MM_jumpMenu(\'parent\',this,0)">
<option>Pick Month...</option>
<option value="event.php?promoter='
.$promoter .'&month=1">January</option>
<option value="event.php?promoter='
.$promoter .'&month=2"">Febuary</option>
<option value="event.php?promoter='
.$promoter .'&month=3">March</option>
<option value="event.php?promoter='
.$promoter .'&month=4">April</option>
<option value="event.php?promoter='
.$promoter .'&month=5">May</option>
<option value="event.php?promoter='
.$promoter .'&month=6">June</option>
<option value="event.php?promoter='
.$promoter .'&month=7">July</option>
<option value="event.php?promoter='
.$promoter .'&month=8">August</option>
<option value="event.php?promoter='
.$promoter .'&month=9">September</option>
<option value="event.php?promoter='
.$promoter .'&month=10">October</option>
<option value="event.php?promoter='
.$promoter .'&month=11">November</option>
<option value="event.php?promoter='
.$promoter .'&month=12">December</option>
</select>
</div>
</form></TD>
</TR>
</TBODY>
</TABLE>

<TABLE width="590" height="22" border=0 cellPadding=1 cellSpacing=1 bordercolor="#000000">
<TBODY>
<TR> 
<TD width=146 height="12" class="mainTextBig">Night:</TD>
<TD width=54 class="mainTextBig">Total names:</TD>
<TD width=65 class="mainTextBig">Confirmed names:</TD>
<TD width=57 class="mainTextBig">View List:</TD>
<TD width=123 class="mainTextBig">Guestlist Day:</TD>
<TD width=56 class="mainTextBig">Delete Event:</TD>
<TD width=67 class="mainTextBig">Update Event:</TD>
</TR>
</TBODY>
</TABLE>'
;
            
// Loop Start 
while ($night=mysql_fetch_assoc($result)) {
echo
'
<TABLE width="590" height="12" border=0 cellPadding=1 cellSpacing=1 bordercolor="#CCCCCC">
<TBODY>
<TR> 
<TD width="200" height="12" class="mainText">'
$night['name'] .' | '$days[$night['iddays']] .'</TD>
<TD width="54" class="mainText">0</TD>
<TD width="64" class="mainText">0</TD>
<TD width="58" class="mainText">
<img src="xls.gif" width="16" height="16"> 
<img src="pdf.gif" width="16" height="16"><a href="http://www.selectguestlist.com/guestlist/list.php?day=26&month=6&night=1"><img src="html.gif" width="16" height="16" border="0"></a></TD>
<TD width="122" class="mainText"> 

<select name="select" class="mainFormBox" style="WIDTH: 120px">'
;


for(
$i=1;$i<$num_weeks;$i++) 

   
$timestamp strtotime('+1 week'$timestamp); 
   echo 
'<option value="' $timestamp '">' date('l d F Y'$timestamp) . '</option>'
}


echo 
'
</select>

</TD>
<form name="delete" method="post" action="delete.php">
<TD width="56" class="mainText">
<input type="hidden" NAME="promoter" VALUE="'
$night['listname'] .'">
<input type="hidden" NAME="night" VALUE="'
$night['idNight'] .'">
<input name="delete" type="submit" class="mainForm" value="Delete">
</TD>
</form>
<form name="update" method="post" action="update.php">
<TD width="67" class="mainText">
<input type="hidden" NAME="night" VALUE="'
$night['idNight'] .'">
<input name="update" type="submit" class="mainForm" value="Update">
</TD>
</form>
</TR>
</TBODY>
</TABLE>'

// Loop End 


Last edited by dihan; 06-29-04 at 07:44 AM.
Reply With Quote
  #10 (permalink)  
Old
NeverMind's Avatar
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
why did you remove $num_weeks ?
change the for() to:
PHP Code:

$num_weeks 4;


for(
$i=1$i<=$num_weeks$i++)
{
   
$timestamp strtotime('+1 week'$timestamp);
   echo 
'<option value="' $timestamp '">' date('l d F Y'$timestamp) . '</option>';

note the equal sign in the second argument of for()!
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP > MSQL - Loop date system dihan PHP 0 06-12-04 05:11 PM
Need day of year from ISO-8601 week number. matt.simpson PHP 1 01-20-04 01:04 PM


All times are GMT -5. The time now is 09:33 PM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.