formating cells need to fill table

sample code reads in weekdays worked and outputs "start" "end" hours for users.
problem - if user(david,les,lee) work fri, sat & sun table shows first 3 cells to the left - mon tue wed
example:
http://america3.pcs.cnu.edu/~jarmstro/sched_array2.php3
????solution???
count weekdays(0-6) and add " " or "off" cells OR
fill one array[] w/ "off" & join with data[]??

db layout:
http://america3.pcs.cnu.edu/~jarmstro/view_table.html

<?
$data=get_user_data1();
?>
<table width=100% >
<?while(list($key,$value)=each($data))
     {?>
<tr><td><?=$key?></td>
<?while(list($key1,$value1)=each($data[$key]))
     {?>
<td><?=$data[$key][$key1][start]?></td>
<td><?=$data[$key][$key1][end]?></td>
<?}?>
</tr>
<?}?>
</table>
<?


function get_user_data1()
     {
$query="select * from TimeTable where weekno=200215 and user<>'' and dept=5 order by user,weekday;
$qid=mysql_query($query);
if($qid){
       $data=array();
       $i=0;
       while($row=mysql_fetch_array($qid)){
           $data[$row[user]][$i++]=$row;}
return $data;
}
else{
      echo 'Error :'.mysql_error();
      exit;}
}
?>

jarmstro12Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
lokeshvConnect With a Mentor Commented:
ok my mistake..sorrie abt that...

try this..

<?php
$db = mysql_connect("localhost", "master");
mysql_select_db("sched",$db);

$data=get_user_data1();
?>
<table width="100%" cellpadding="0" cellspacing="0">
<?
for($i=0;$i<count($data);$i++){
$day=$data[$i][weekday];
print $day;
?>
<tr>
<td><?=$data[$i][user]?></td>
<td><? if($day==0){echo $data[$i][start];} else{echo '&nbsp;';}?></td>
<td><? if($day==0){echo $data[$i][end];}else{echo '&nbsp;';}?></td>
<td><? if($day==1){echo $data[$i][start];}else{echo '&nbsp;';}?></td>
<td><? if($day==1){echo $data[$i][end];}else{echo '&nbsp;';}?></td>
<td><? if($day==2){echo $data[$i][start];}else{echo '&nbsp;';}?></td>
<td><? if($day==2){echo $data[$i][end];}else{echo '&nbsp;';}?></td>
<td><? if($day==3){echo $data[$i][start];}else{echo '&nbsp;';}?></td>
<td><? if($day==3){echo $data[$i][end];}else{echo '&nbsp;';}?></td>
<td><? if($day==4){echo $data[$i][start];}else{echo '&nbsp;';}?></td>
<td><? if($day==4){echo $data[$i][end];}else{echo '&nbsp;';}?></td>
<td><? if($day==5){echo $data[$i][start];}else{echo '&nbsp;';}?></td>
<td><? if($day==5){echo $data[$i][end];}else{echo '&nbsp;';}?></td>
<td><? if($day==6){echo $data[$i][start];}else{echo '&nbsp;';}?></td>
<td><? if($day==6){echo $data[$i][end];}else{echo '&nbsp;';}?></td>
</tr>
<?}?>
</table>
<?
function get_user_data1()
{
$query="select * from TimeTable where weekno=200215 and user<>'' and dept=5 order by user,weekday";
$qid=mysql_query($query);
if($qid){
$data=array();

for($i=0;$i<mysql_num_rows($qid);$i++){
    $data[$i]=mysql_fetch_array($qid);
}

return $data;
}
else{
echo 'Error :'.mysql_error();
exit;}
}
?>

 
Hope this works..

Lk
 

0
 
lokeshvCommented:
try this...

<?
$data=get_user_data1();
?>
<table width=100% >
<?while(list($key,$value)=each($data))
    {?>
<tr><td><?=$key?></td>
<?while(list($key1,$value1)=each($data[$key]))
    {?>
<td><?if(($data[$key][$key1][start]!="NULL)||)($data[$key][$key1][start]!=="")){echo $data[$key][$key1][start];} else { echo 'nbsp;';}?></td>
<td>><?if(($data[$key][$key1][end]!="NULL)||($data[$key][$key1][end]!=="")){echo $data[$key][$key1][end];} else { echo 'nbsp;';}?></td>
<?}?>
</tr>
<?}?>
</table>
<?


function get_user_data1()
    {
$query="select * from TimeTable where weekno=200215 and user<>'' and dept=5 order by user,weekday;
$qid=mysql_query($query);
if($qid){
      $data=array();
      $i=0;
      while($row=mysql_fetch_array($qid)){
          $data[$row[user]][$i++]=$row;}
return $data;
}
else{
     echo 'Error :'.mysql_error();
     exit;}
}
?>

hope this helps..

LK
0
 
lokeshvCommented:
some typo errors ..in previous...one try this..

<?
$data=get_user_data1();
?>
<table width=100% >
<?while(list($key,$value)=each($data))
   {?>
<tr><td><?=$key?></td>
<?while(list($key1,$value1)=each($data[$key]))
   {?>
<td><?if(($data[$key][$key1][start]!="NULL")||($data[$key][$key1][start]!=" ")){echo $data[$key][$key1][start];}
else { echo 'nbsp;';}?></td>
<td>><?if(($data[$key][$key1][end]!="NULL")||($data[$key][$key1][end]!=" ")){echo $data[$key][$key1][end];}
else { echo 'nbsp;';}?></td>
<?}?>
</tr>
<?}?>
</table>
<?


function get_user_data1()
   {
$query="select * from TimeTable where weekno=200215 and user<>'' and dept=5 order by user,weekday;
$qid=mysql_query($query);
if($qid){
     $data=array();
     $i=0;
     while($row=mysql_fetch_array($qid)){
         $data[$row[user]][$i++]=$row;}
return $data;
}
else{
    echo 'Error :'.mysql_error();
    exit;}
}
?>

hope this helps..

LK
 
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
BatalfCommented:
Or you could use a counter to keep track of how many cells you have been written to at each row. That's a simple and safe method.

Something like this

<?
$data=get_user_data1();
?>
<table width=100% >
<?while(list($key,$value)=each($data))
{?>
   <tr><td><?=$key?></td>
   <?
   $myCounter=0;
   while(list($key1,$value1)=each($data[$key]))
   {?>
      <td><?=$data[$key][$key1][start]?></td>
      <td><?=$data[$key][$key1][end]?></td>
      <?
      $myCounter++;
   }

   for($no=$myCounter;$no<7;$no++){echo "<td>&nbsp;</td><td>&nbsp;</td>";}
   ?>
</tr>
<?}?>
</table>
<?


0
 
lokeshvCommented:
I think Batalf i think u took his problem in a wrong way..

by ur way all data columns will be displayed first and the rest of the columns will be filled by "nbsp;"


in that case the columns wil get mix suppose  a user has data for only Saturday then by ur method it will be displayed under monday..

rite?

Lk




0
 
BatalfCommented:
You're probably right. I didn't read the question carefully enough.

Batalf
0
 
jarmstro12Author Commented:
I'm unsure about this error - need a debugger.
parse error expecting ']' line 31 at:
"$data[$row[user]][$i++]=$row;}"

<?php
 $db = mysql_connect("localhost", "master");
  mysql_select_db("sched",$db);

$data=get_user_data1();
?>
<table width=100%>
<?while(list($key,$value)=each($data))
{?>
<tr><td><?=$key?></td>
<?while(list($key1,$value1)=each($data[$key]))
{?>
<td><?if(($data[$key][$key1][start]!="NULL")||($data[$key][$key1][start]!=" ")){echo $data[$key][$key1][start];}
else { echo 'nbsp;';}?></td>
<td>><?if(($data[$key][$key1][end]!="NULL")||($data[$key][$key1][end]!=" ")){echo $data[$key][$key1][end];}
else { echo 'nbsp;';}?></td>
<?}?>
</tr>
<?}?>
</table>

<?
function get_user_data1()
{
$query="select * from TimeTable where weekno=200215 and user<>'' and dept=5 order by user,weekday;
$qid=mysql_query($query);
if($qid){
$data=array();
$i=0;
while($row=mysql_fetch_array($qid)){
$data[$row[user]][$i++]=$row;}
return $data;
}
else{
echo 'Error :'.mysql_error();
exit;}
}
?>









0
 
lokeshvCommented:
ok parse error fixed try the code below..




<?php
$db = mysql_connect("localhost", "master");
 mysql_select_db("sched",$db);

$data=get_user_data1();
?>
<table width=100%>
<?while(list($key,$value)=each($data))
{?>
<tr><td><?=$key?></td>
<?while(list($key1,$value1)=each($data[$key]))
{?>
<td><?if(($data[$key][$key1][start]!="NULL")||($data[$key][$key1][start]!=" ")){echo $data[$key][$key1][start];}
else { echo 'nbsp;';}?></td>
<td>><?if(($data[$key][$key1][end]!="NULL")||($data[$key][$key1][end]!=" ")){echo $data[$key][$key1][end];}
else { echo 'nbsp;';}?></td>
<?}?>
</tr>
<?}?>
</table>

<?
function get_user_data1()
{
$query="select * from TimeTable where weekno=200215 and user<>'' and dept=5 order by user,weekday";
$qid=mysql_query($query);
if($qid){
$data=array();
$i=0;
while($row=mysql_fetch_array($qid)){
$data[$row[user]][$i++]=$row;}
return $data;
}
else{
echo 'Error :'.mysql_error();
exit;}
}
?>

hope this helps..

Lk
0
 
jarmstro12Author Commented:
If there is any other tests that I can do?

each user only works one day and on a different day.
an interesting output:
http://america3.pcs.cnu.edu/~jarmstro/5up.html

using the same test table as before:
http://america3.pcs.cnu.edu/~jarmstro/view_table1.html
weekno = 200233 dept=6

notice 5 day shown for 7 day week
using another dept and week:
http://america3.pcs.cnu.edu/~jarmstro/dept5.html
0
 
jarmstro12Author Commented:
Lk
 more testing
new tables:
 - gary works all 7 days
http://america3.pcs.cnu.edu/~jarmstro/gary7.html

 - gary works 6 days w/ tue off
http://america3.pcs.cnu.edu/~jarmstro/gary6.html


0
 
lokeshvCommented:
ok i got ur problem now...check this ..

<?php
$db = mysql_connect("localhost", "master");
mysql_select_db("sched",$db);

$data=get_user_data1();
?>
<table width="100%" cellpadding="0" cellspacing="0">
<?
for($i=0;$i<count($data);$i++){
$day=$data[$i][weekday];
?>
<tr>
<td><?=$data[$i][user]?></td>
<td><? if($day==0){echo $data[$i][start];)else{echo 'nbsp;';}?></td>
<td><? if($day==0){echo $data[$i][end];)else{echo 'nbsp;';}?></td>
<td><? if($day==1){echo $data[$i][start];)else{echo 'nbsp;';}?></td>
<td><? if($day==1){echo $data[$i][end];)else{echo 'nbsp;';}?></td>
<td><? if($day==2){echo $data[$i][start];)else{echo 'nbsp;';}?></td>
<td><? if($day==2){echo $data[$i][end];)else{echo 'nbsp;';}?></td>
<td><? if($day==3){echo $data[$i][start];)else{echo 'nbsp;';}?></td>
<td><? if($day==3){echo $data[$i][end];)else{echo 'nbsp;';}?></td>
<td><? if($day==4){echo $data[$i][start];)else{echo 'nbsp;';}?></td>
<td><? if($day==4){echo $data[$i][end];)else{echo 'nbsp;';}?></td>
<td><? if($day==5){echo $data[$i][start];)else{echo 'nbsp;';}?></td>
<td><? if($day==5){echo $data[$i][end];)else{echo 'nbsp;';}?></td>
<td><? if($day==6){echo $data[$i][start];)else{echo 'nbsp;';}?></td>
<td><? if($day==6){echo $data[$i][end];)else{echo 'nbsp;';}?></td>
</tr>
<?}?>
</table>
<?
function get_user_data1()
{
$query="select * from TimeTable where weekno=200215 and user<>'' and dept=5 order by user,weekday";
$qid=mysql_query($query);
if($qid){
$data=array();
$i=0;
while($row=mysql_fetch_array($qid)){
$data[$row[user]][$i++]=$row;}
return $data;
}
else{
echo 'Error :'.mysql_error();
exit;}
}
?>



Hope this helps..

Lk
0
 
jarmstro12Author Commented:
Lk
 - switched ) for } in );{else
 and added 'print nbsp;'  didnt print numbers see:
http://america3.pcs.cnu.edu/~jarmstro/nbsp.html

<?php
$db = mysql_connect("localhost", "master");
mysql_select_db("sched",$db);

$data=get_user_data1();
?>
<table width="100%" cellpadding="0" cellspacing="0">
<?
for($i=0;$i<count($data);$i++){
$day=$data[$i][weekday];
print $day;
?>
<tr>
<td><?=$data[$i][user]?></td>
<td><? if($day==0){echo $data[$i][start];} else{echo 'nbsp;';}?></td>
<td><? if($day==0){echo $data[$i][end];}else{echo 'nbsp;';}?></td>
<td><? if($day==1){echo $data[$i][start];}else{echo 'nbsp;';}?></td>
<td><? if($day==1){echo $data[$i][end];}else{echo 'nbsp;';}?></td>
<td><? if($day==2){echo $data[$i][start];}else{echo 'nbsp;';}?></td>
<td><? if($day==2){echo $data[$i][end];}else{echo 'nbsp;';}?></td>
<td><? if($day==3){echo $data[$i][start];}else{echo 'nbsp;';}?></td>
<td><? if($day==3){echo $data[$i][end];}else{echo 'nbsp;';}?></td>
<td><? if($day==4){echo $data[$i][start];}else{echo 'nbsp;';}?></td>
<td><? if($day==4){echo $data[$i][end];}else{echo 'nbsp;';}?></td>
<td><? if($day==5){echo $data[$i][start];}else{echo 'nbsp;';}?></td>
<td><? if($day==5){echo $data[$i][end];}else{echo 'nbsp;';}?></td>
<td><? if($day==6){echo $data[$i][start];}else{echo 'nbsp;';}?></td>
<td><? if($day==6){echo $data[$i][end];}else{echo 'nbsp;';}?></td>
</tr>
<?}?>
</table>
<?
function get_user_data1()
{
$query="select * from TimeTable where weekno=200215 and user<>'' and dept=5 order by user,weekday";
$qid=mysql_query($query);
if($qid){
$data=array();
$i=0;
while($row=mysql_fetch_array($qid)){
$data[$row[user]][$i++]=$row;}
return $data;
}
else{
echo 'Error :'.mysql_error();
exit;}
}
?>

0
 
jarmstro12Author Commented:
I meant - added 'print $day;' and no numbers printed
0
 
jarmstro12Author Commented:
0
 
lokeshvCommented:
remove the print $day;

i think script is just fine...

just check on ur test data table


Lk
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.