Solved

formating cells need to fill table

Posted on 2002-05-17
15
214 Views
Last Modified: 2006-11-17
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;}
}
?>

0
Comment
Question by:jarmstro12
  • 7
  • 6
  • 2
15 Comments
 
LVL 4

Expert Comment

by:lokeshv
ID: 7017938
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
 
LVL 4

Expert Comment

by:lokeshv
ID: 7018081
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
 
LVL 32

Expert Comment

by:Batalf
ID: 7018240
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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 4

Expert Comment

by:lokeshv
ID: 7018249
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
 
LVL 32

Expert Comment

by:Batalf
ID: 7018252
You're probably right. I didn't read the question carefully enough.

Batalf
0
 

Author Comment

by:jarmstro12
ID: 7018432
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
 
LVL 4

Expert Comment

by:lokeshv
ID: 7018458
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
 

Author Comment

by:jarmstro12
ID: 7018731
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
 

Author Comment

by:jarmstro12
ID: 7018782
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
 
LVL 4

Expert Comment

by:lokeshv
ID: 7018800
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
 

Author Comment

by:jarmstro12
ID: 7019089
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
 

Author Comment

by:jarmstro12
ID: 7019095
I meant - added 'print $day;' and no numbers printed
0
 
LVL 4

Accepted Solution

by:
lokeshv earned 500 total points
ID: 7019123
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
 

Author Comment

by:jarmstro12
ID: 7019128
0
 
LVL 4

Expert Comment

by:lokeshv
ID: 7019137
remove the print $day;

i think script is just fine...

just check on ur test data table


Lk
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question