question about the week's data read and show

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dears,

Here is my question:

I am write a project manage system.

Now I need to echo one week’s data and send to html show.

Any one got a good idea or codes?

My code has some issues about the loop function. Could you help me check or give me some suggestion?

The show item like this:

********************************

This week is 25.th week of 2008

[Last Week]06/09--06/15// can be link and show the different week’s data

[This Week]06/16--06/22

[Next Week]06/23--06/29

Found 2 records in 23’Th week.

=======================================================================================

NAME\DAY         06/09 Monday    06/10 Tuesday   06/11 Wednesday      06/12 Thursday  06/13 Friday      06/14 Saturday  06/15 Sunday

Cathy                00                     08361-sb           02                             03                     04                     05                     06

James               10                     08362-sb           12                             13               08362-sb                15                     16

Connie              20                     21                     08740-sa                   23                     24                     25                     26

Ken                   30                     31                     08741-sb                   33                     34                     08741-sb           36

========================================================================================

My code here (But it seems that some issues on show)

<?php

 //==========================Link to the database==========================================

  $link = mysql_connect('localhost', 'evel', '000000')//link the database

    or die('Could not connect: ' . mysql_error());

  mysql_select_db('evel') or die('Could not select database');

 //==========================show the week information===================================

  $weeknumber=date(W);

  $yearnumber=date(Y);

  $tt=week_limits($weeknumber,$yearnumber);

  $begin=date("m/d l",1212973261);

  $end=date("m/d l", 1213491661);

  echo "This week is $weeknumber th week of $yearnumber<br>";

  echo "Date from $begin($tt[0]) to $end($tt[1])<br>";

 //=======================================================================================

 

 //==========================show the weekdate table======================================

    $lowEnd=date("w");

    $lowEnd=-$lowEnd;

    $highEnd=$lowEnd +7;

    $weekday=0;

    $weektr.= "<link href=\"require/style.css\" rel=\"stylesheet\" type=\"text/css\">\n";

    $weektr.= "<table width=\"118\" bgcolor=\"#FFFFFF\" align=center>\n";

    $weektr.= "<tr>\n";

    $weektr.= "<TD class=\"Content\"><FONT COLOR=BLUE><B>NAME\DAY</B></FONT></TD>";

    for ($i=$lowEnd+1;$i<=$highEnd;$i++)

    {

      $WeekDate[$weekday]=date("m/d l",mktime(0, 0, 0, date("m")  , date("d")+$i, date("Y")));

      $datename[$weekday]=date("N",mktime(0, 0, 0, date("m")  , date("d")+$i, date("Y")));

      

      $weektr.= "<TD nowrap align=center bgcolor=\"F1F1F1\">";

      $weektr.= "$WeekDate[$weekday]";

      $weektr.= "</TD>\n";

    }

 //===============================end of weekdate====================================================

 //=================================show the data ====================================================

    $result = mysql_query("select PNB,Name,Time from report where Time>='1212138371' AND Time<='1212886861'");//weelresult one week time area test

    $num=mysql_num_rows($result);

    // echo $num;//show the record number,control the table

    if($num)

    {

    echo "Found $num records<br>";

    $weektr.= "<tr>\n";

   // while($myrow=mysql_fetch_array($result,MYSQL_NUM))

   // {

   // $weekdaynumber=date("N",$myrow[2]);

        for($x = 0;$x < $num;$x++)//create the data array,for the search resule number

        {

        $weekdaynumber=date("N",$myrow[2]);

                for($y = 0;$y < 7;$y++)//loop for tr

                {

                 for($i=0;$i<8;$i++)

                  {

                   if($weekdaynumber==$y)//get the relate week date data

                   {

                    $data[$x][$y] =$myrow[0];

                   }

                   else

                    $data[$x][$y] ="$x$y";

                  }

                 $mat[$x][$y] = "$x,$y";

                }

               

        }

        

         //echo $weekdaynumber;

        

    while ($x= mysql_fetch_row($result))//one by one show the data record

  {      $x=0;

        // for($x = 0;$x <= mysql_fetch_row($result);$x++){

      //  for($x = 0;$x < count($data[$x]);$x++)//output the data,as the dataarray number is 

      //  {

               for($y = 0;$y <7;$y++)

                {

                 if($y==0)//devide the cell to name and the week date and project cell

                  {

                   $weektr.="<td  align=\"center\">$myrow[1]</td>";

                   $weektr.="<td  align=\"center\">".$data[$x][$y]."</td>";

                  }

                 else

                   $weektr.="<td  align=\"center\">".$data[$x][$y]."</td>";

                }

                $x++;

        $weektr.= "</tr>\n";

       // }

      // }

   }

  }

    else 

    echo "Found 0 records";

  $weektr.="</table>\n";

  print $weektr;

 //===============================end of weekdate====================================================

 

 //=================================get the week time area(seconds) =================================

  

   function week_limits($weekNumber, $year)

        {

            // begin datetime

            $time = mktime(1, 1, 1, 1, 1, $year);            

            // Aassuring that $weekNumber is number

            $weekNumber--;

            // If first week of year starts not from monday, 

            //date() will return "not correct" result (in this case first week is 0)

            if (date('w', $time) == 1)

                $weekNumber++;

            $start_time = false;

            $end_time = false;

            for ($day = 1; $day <= 380; $day++)

            {

                if (date('W', $time) == $weekNumber && !$start_time)

                    $start_time = $time;

                if (date('W', $time - 24*60*60) == $weekNumber && !$end_time && date('W', $time) != $weekNumber)

                    $end_time = $time - 24*60*60;               

                if ($start_time && $end_time)

                    break;

                $time += 24*60*60;

            }

            return array($start_time, $end_time);

        }

 //=================================End of week_limits()=================================

?>

 

 

 

Regards!

Evel#0616


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux