Jump to content

Looping


Fearpig

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
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.