Jump to content


Photo

Can Anyone Dare To Solve This


  • This topic is locked This topic is locked
3 replies to this topic

#1 ankycooper

ankycooper
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 29 September 2006 - 11:18 AM

hi i have a database in which there are following fields
name
month
startdate
enddate
starttime
endtime
wf1
wf2
wf3

lets take a sample data
jay peter
march
2006-09-03
2006-09-24
07:00
16:00
Saturday
Sunday
NA

there are sevral such records

i want to populate a table like this (see the attachment)

Need some help

But The code only populates 1st  record
<html>
<link rel="stylesheet" type="text/css" href="../scripts/main.css" >
<head>
<title>Roster Management System</title>
</head>

<body bgcolor="#C7E1F4">
<div align="center">
  <center>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#EEEEEE">
  <tr style="font-size: 12px; color: #ffffff; font-family: Arial, Helvetica, sans-serif">
    
    <td class="info" style='border:1px solid #C7E1F4; background-color: #2955B5' width="100" height="1">
    <p align="left"><b><font color='#FFFFFF'>&nbsp;Date&nbsp;&nbsp;</font></b></td>
	<td class="info" style="border:1px solid #C7E1F4; background-color: #2955B5" width="65" height="1">
    <p align="left"><b><font color='#FFFFFF'>&nbsp;Day&nbsp;&nbsp;</font></b></td>
	<td class="info" style="border:1px solid #C7E1F4; background-color: #2955B5" width="100" height="1">
    <p align="left"><b><font color='#FFFFFF'>&nbsp;Time&nbsp;&nbsp;</font></b></td>

<?php
function dateconvert($date,$func) {
		if ($func == 1){ //insert conversion
			list($day, $month, $year) = split('[/.-]', $date); 
			$date = "$year-$month-$day"; 
			return $date;
		}
		if ($func == 2){ //output conversion
			list($year, $month, $day) = split('[-.]', $date); 
			$date = "$day/$month/$year"; 
			return $date;
		}
}

$mmyy=$_GET['mmyy'];

include '../config/dbinfo.inc.php';
@mysql_connect($host,$user_name,$pass_word);
@mysql_select_db($database) or die( "Unable to select database");
$sql = "SELECT * FROM emproster where mmyy='$mmyy'";
 $sql = "SELECT * FROM emproster where mmyy='$mmyy'";
  $res = mysql_query($sql) or die (mysql_error());
  $r = mysql_fetch_assoc($res);
  echo "<td class='info' style='border:1px solid #C7E1F4; background-color: #2955B5' width='150' height='1'>
    <p align='left'><b><font color='#FFFFFF'>&nbsp;".$r['name']."</font></b></td>";
	 echo "</tr>";
  $days = (date("j", strtotime($r['edate'])) - date("j", strtotime($r['sdate']))) + 1;
  $sdate = date("Y-m-d", strtotime($r['sdate']));
  for($i=0; $i<$days; $i++){
    $day = date("D", strtotime($sdate));
    $fullday = date ("l", strtotime($sdate));
      if($fullday == $r['wf1'])
		  {
        $st_time = "<span style='background-color: #FF0000'><b><font color='#FFFFFF'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WOFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></b></span>";
        $e_time = "<span style='background-color: #FF0000'><b><font color='#FFFFFF'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WOFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></b></span>";
      } 

	  elseif($fullday == $r['wf2'])
		  {
         $st_time = "<span style='background-color: #FF0000'><b><font color='#FFFFFF'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WOFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></b></span>";
        $e_time = "<span style='background-color: #FF0000'><b><font color='#FFFFFF'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WOFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></b></span>";
      } 
	  elseif($fullday == $r['wf3']){
        $st_time = "<span style='background-color: #FF0000'><b><font color='#FFFFFF'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WOFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></b></span>";
        $e_time = "<span style='background-color: #FF0000'><b><font color='#FFFFFF'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WOFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></b></span>";
      } 
	  else {

        $st_time = "<b><font color='#2955B5'><span style='background-color: #FFFF99'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$r['stime']."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font></b>";
        $e_time = "<b><font color='#2955B5'><span style='background-color: #CCFF99'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$r['etime']."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font></b>";
      }
	  $sdate=dateconvert($sdate, 1);
	  echo "<tr>";
   
	echo "<td class='back2' style='border:1px solid #C7E1F4; background-color: #CED7EF' rowspan=2><b><font color='#2955B5'>&nbsp;$sdate</b></font></td>";
    echo "<td class='back2' style='border:1px solid #C7E1F4; background-color: #CED7EF' rowspan=2><b><font color='#2955B5'>&nbsp;$day</b></font></td>";
    echo "<td class='back2' style='border:1px solid #C7E1F4; background-color: #CED7EF'><b><font color='#2955B5'>&nbsp;Report Time</b></font></td>";
    echo "<td class='back2' style='border:1px solid #C7E1F4; background-color: #CED7EF'>$st_time</td>";
    echo "</tr>";
    echo "<tr>";
   
	echo "<td class='back2' style='border:1px solid #C7E1F4; background-color: #CED7EF'><b><font color='#2955B5'>&nbsp;Drop Time</b></font></td>";
    echo "<td class='back2' style='border:1px solid #C7E1F4; background-color: #CED7EF'>$e_time</td>";
    echo "</tr>";
    $sdate = date("Y-m-d", strtotime("$sdate +1 day"));
  }
  echo "</table>";
?>


  </center></div>


[attachment deleted by admin]

#2 HuggieBear

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

Posted 29 September 2006 - 11:53 AM

Yeah, it looks as though you need a while loop around the whole thing.

Where you have:

<?php
$r = mysql_fetch_assoc($res);
// All your code here
?>

You should probably have:

<?php
while ($r = mysql_fetch_assoc($res)){
   // All your code here
}
?>

This basically says, while there's still rows in the mysql resource, loop through.

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 ankycooper

ankycooper
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 30 September 2006 - 09:03 PM

while repeats the entire thing
i just want the last column to be repeated

Please help

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 30 September 2006 - 10:59 PM

Do not double post

Read the forum guidelines

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users