Jump to content

Display a certain list of days using date()


jdorma0

Recommended Posts

Basically,  I need to prefill a select drop down box with the sunday of each week. I would like to it to basically be in the format of:

 

<select name="row_date">
<option value="2010-01-01">2010-01-01</option>
<option value="2010-01-08">2010-01-08</option>
<option value="2010-01-15">2010-01-15</option>
<option value="2010-01-22">2010-01-22</option>
etc.
etc.
</select>

But it would automatically select the current week (as the default value) and allow the user to change that.. but only from the displayed dates. I wouldn't need more than 6 weeks to be shown, but that's not too important.

 

I've researched this forum, php.net and Google to no avail. Hopefully one of you bright people can help me out!

 

Thanks! =]

Joey

Link to comment
Share on other sites

$time = strtotime("next sunday");
$week = 60*60*24*7;//60 secs a min * 60 mins an hour * 24 hours a day * 7 days a week

for ($i = 0; $i < 10; $i++){
echo date("Y-m-d", $time) . "<br />";
$time += $week;
}

 

that should help get you started. its gets the next sunday of the week, and outputs the next 10. its pretty simple logic wise, but you may want to put in a check to see if its a sunday, if you want to list the current day if its a sunday.

Link to comment
Share on other sites

$time = strtotime("next sunday");
$week = 60*60*24*7;//60 secs a min * 60 mins an hour * 24 hours a day * 7 days a week

for ($i = 0; $i < 10; $i++){
echo date("Y-m-d", $time) . "<br />";
$time += $week;
}

 

that should help get you started. its gets the next sunday of the week, and outputs the next 10. its pretty simple logic wise, but you may want to put in a check to see if its a sunday, if you want to list the current day if its a sunday.

Thanks so much! With a little modification:

 

$week = 60*60*24*7;//60 secs a min * 60 mins an hour * 24 hours a day * 7 days a week
$time = strtotime("last sunday");

for ($i = 0; $i < 10; $i++){
        $etime = "<option value=\"".date("Y-m-d", $time)."\"";
        if($i==1) {
         $etime .="selected";
        }
        $etime .= ">".date("Y-m-d", $time) . "</option>";
        echo $etime;
        $time -= $week;
}

 

It works like a charm! I appreciate it.

Link to comment
Share on other sites

no problem. if your topic is solved you can click the mark solved button at the bottom of the thread

 

Yes sir.

 

I know I should start another topic for this, but maybe you will know the answer. I need to prefill a select field for each row of my form.

 

echo "<div align=\"center\"><font color=\"red\"><b>WARNING:</b> Only use the results for the week ending on <b>".$vars['emp_date']."</b></font></div><br />";
?>
<table align="center" class="style6">
	<tr>
		<th>Employee</th>
		<th>Star</th>
		<th>CSAT</th>
		<th>CPH</th>
		<th>PA</th>
		<th>Credit</th>
		<th>Attachments</th>
                        		
	</tr>
<?php
echo '<form action="insert.php" method="post">';

$i=0;

while($i<$vars['emp_num']) {
    $emp = "<tr><td><select name=\"row_associd_$i\">";
$res = mysql_query("SELECT * FROM employees WHERE department='".$_POST['emp_department']."'");
    $emp .= "<option \"\">Select Employee</option>";
    
while($emps = mysql_fetch_array($res)) {
    $emp .= "<option value=".$emps['associd'];
    
    //    $emp .=" selected"; // Need to decide how to get this to output, skipping the last person
        
   
    
    $emp .=">".$emps['fname']." ".$emps['lname']."</option>";
    
    }
    
    $emp .= "</select></td>";
    $emp .= "<td><input type=\"text\" size=\"5\" name=\"row_star_$i\">";
    $emp .= "</td><td><input type=\"text\" size=\"5\" name=\"row_csat_$i\">";
    $emp .= "</td><td><input type=\"text\" size=\"5\" name=\"row_cph_$i\">";
    $emp .= "</td><td><input type=\"text\" size=\"5\" name=\"row_pa_$i\">";
    $emp .= "</td><td><input type=\"text\" size=\"5\" name=\"row_credit_$i\">";
    $emp .= "</td><td><input type=\"text\" size=\"5\" name=\"row_attachments_$i\">";
    $emp .= "</td></tr>";
    echo $emp;
    $i++;
}
?>

</table>
<input type="hidden" name="emp_i" value="<?php echo $i;?>">
<input type="hidden" name="action" value="emp_processrows">

<input type="submit" name="emp_submit" value="rank employees">
</form>

 

Basically, I would like to have selected each person for the row.

 

Example:

 

Bob Jones - selected
Mary Beth - not selected
Frank Sinatra - not selected

Bob Jones - not selected
Mary Beth - selected
Frank Sinatra - not selected

Bob Jones - not selected
Mary Beth - not selected
Frank Sinatra - selected

 

I was playing around with it but I couldn't get it figured out. I'd appreciate it if you could help me with that one too.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.