Jump to content

Archived

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

Fearpig

Looping

Recommended Posts

Hello,
Bit of a vague question for someone!  ??? I'm trying to loop some PHP so that it displays a set of results, increases one of the parameters and displays the next set. It needs to stop looping on the 7th pass!

Basically I need it to list todays jobs, then list the next days jobs ... up to a week. I can't just order by date as I need them grouped and not just in a list.

Here's a rough idea of the code but there are lots of errors... could someone point me in the right direction or send me a link to a tutorial.  :)

<?php
$day=0
//sets the day value back to 0 - days run 0,1,2,3,4,5,6,

$startdate=date("Y/m/d")
//sets the initial date to the current date

while ($day < 7)
{
//not sure if I can write conditions like this!
     
      $selectdate = date( "Ymd", mktime(0, 0, 0, date("m"), date("d")+$day, date("y")) );
      //increase $startdate by the current value of $day

      $conn=odbc_connect('OU_PROD','ou_dba','dba');
      if (!$conn)
            {exit("Connection Failed: " . $conn);}
      $sql="SELECT request_id, date FROM assignment WHERE date = '$selectdate'";
      $rs=odbc_exec($conn,$sql);
      if (!$rs)
            {exit("Error in SQL");}

      echo "$selectdate<br>";

    while (odbc_fetch_row($rs))
    {
          $Request=odbc_result($rs,"request_id");
          echo "$Request<br>";
    }



$day = ($day +1)
//fairly sure that this won't work as it refers to itself!

}

?>

Any help would be appreciated as this will remove a load of nearly identical pages.
Cheers
Tom

Share this post


Link to post
Share on other sites
Hi,

Change:
[code=php:0]$day = ($day +1);
[/code]

To:
[code=php:0]$day++;
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
Thanks Huggiebear! I'll have a play with that and see what I can do.

(It always seems to be you or Wildteen that helps me!)

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.