Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

formating cells need to fill table

Posted on 2002-05-17
15
Medium Priority
?
220 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.
Suggested Courses

886 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