Jump to content

Archived

This topic is now archived and is closed to further replies.

purefusion

Script that generates the next few Tues/Thurs pairs and stores them in a numbered array

Recommended Posts

Hey, I'm looking for a [b][i]simple[/i][/b] script that generates the next few Tues/Thurs pair combinations and stores them in a numbered array. Simple enough?

For example: If today is Monday the 13, array[1] = Tuesday14, array[2] = Thursday16, etc
I would like to have this rule: if today is Tuesday already, start with the next Thursday, and vice-versa.

They will be echoed in a loop that generates a drop down box in a form such as:

[code]    <select name="select">
      <option value="tues14">Tuesday</option>
      <option value="thurs16">Thursday</option>
      < ... etc ... >
    </select>
[/code]

Hoping you can point me along in the direction of simple coding, as something I'd come up with would to too over-coded and would probably take forever to render.

Thanks so much!

Share this post


Link to post
Share on other sites
try

[code]$today = mktime(0,0,0);
$arr = array();

for ($d=1; $d<=30; $d++) {
     $dt = strtotime("+$d days", $today);
     //get day of week
     $dow = date('w', $dt);
     // store dateval in array
     if (($dow==2) || ($dow==4)) $arr[] = $dt;
}

// print options
echo "<SELECT name='days'>\n";
foreach ($arr as $dt) {
         printf ("<option value='%s'>%s</option>\n", date('Dd', $dt), date('l j', $dt));
}
echo "</SELECT>\n";[/code]

Share this post


Link to post
Share on other sites
That's simple, but does a little extra work. As soon as you find one, most of your work is done. Shouldn't be a big deal either way though.

[code]$today = mktime(0,0,0);
$arr = array();
$adv = 1;

for ($d=1; $d<=30; $d += $adv) {
     $dt = strtotime("+$d days", $today);
     //get day of week
     $dow = date('w', $dt);
     // store dateval in array
     if (($dow==2) || ($dow==4)) $arr[] = $dt;
     if ($dow == 2) $adv = 2;
     if ($dow == 4) $adv = 5;
}

// print it like Barand showed you[/code]

Share this post


Link to post
Share on other sites

×

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.