Solved

formating cells need to fill table

Posted on 2002-05-17
15
212 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now