Jump to content


Photo

Looping


  • Please log in to reply
3 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 28 September 2006 - 12:33 PM

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
"Whats wrong with the cat?" - Mrs Schrödinger

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 12:36 PM

Hi,

Change:
$day = ($day +1);

To:
$day++;

Regards
Huggie


Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 28 September 2006 - 01:35 PM

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!)
"Whats wrong with the cat?" - Mrs Schrödinger

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 01:36 PM

That's because we're sad and sit on here all day  :D

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users