Forum Moderators: coopster

Message Too Old, No Replies

looping with row and column

T_t...

         

nanat

8:22 am on Oct 13, 2009 (gmt 0)

10+ Year Member



hi every one im here again for looping issues. about my reports. it took me days to solve it but i cant find it..
looping attitude are pain in my head.. :(
expected result..
123 (value);
TAB (HORIZONTAL HEADER NAME);
AA BB CC (vertical name);

__TAB
AA123
BB123
CC123

Database structure:
value

1
1
1
2
2
2
3
3
3

vertical name

AA
BB
CC

my codes:


<table width="942" border="1">
<tr>
<td width="186">&nbsp;</td>

<?php
$result = mssql_query("select t0.*, t1.Lname, t1.GroupID from HB1group t0
inner join HB1location t1 on t0.GID = t1.GroupID and t1.GroupID ='$GroupID'");
$exist = mssql_num_rows($result);

if($exist > 0)
{
for ($i = 0; $i < $exist; $i++)
{
$Lname = mssql_result($result, $i, "Lname");

echo '<th><h1 class="flue">'.$Lname.'</h1></th>';
}
}
else
{
echo '<h1 class="flue">NO Entry</h1>';

}

?>

</tr>
<?php

$resulta = mssql_query("select t0.*, t1.* from TTransactionTable t0
inner join HB1location t1 on t1.LocationID = t0.Grouping where t0.Groupid = '2' and t0.WeekNo = '2' and t0.GetDate = '10/13/2009'");
$row = mssql_num_rows($resulta);

$resultz = mssql_query("select * from vessel");
$col = mssql_num_rows($resultz);

echo $row;

$x=0;
while ($x < $col)
{
$VesselName= mssql_result($resultz, $x, "VesselName");
?>
<tr>
<td><?=$VesselName?></td>
<?
$y=0;
while ($y < $row)
{
$inputTable= mssql_result($resulta, $y , "inputTable");
?>
<td><?=$inputTable?></td>
<?
$y++;
}

?>
</tr>
<?
$x++;
}
?>
</table>

result:
__TAB
AA111222333
BB111222333
CC111222333 T_T..

im very thankfull if somebody help.. thx..

nanat

9:33 am on Oct 13, 2009 (gmt 0)

10+ Year Member



tnx guys i got it..

<?php

$resultz = mssql_query("select * from vessel");
$col = mssql_num_rows($resultz);

for($b=0; $b < $col; $b++)
{
$WeekID= mssql_result($resultz, $b, "WeekID");
$VesselName = mssql_result($resultz, $b, "VesselName");

?>
<tr>
<td><?=$VesselName?></td>

<?

$sum = 0;

$resulta = mssql_query("select t0.*, t1.* from TTransactionTable t0
inner join HB1location t1 on t1.LocationID = t0.Grouping where t0.VID=".$WeekID." and t0.Groupid = '2' and t0.WeekNo = '2' and t0.GetDate = '10/13/2009'");
$row = mssql_num_rows($resulta);

for($c=0; $c < $row; $c++)
{
$inputTable= mssql_result($resulta, $y , "inputTable");
$sum = $sum + $inputTable;

$sumM=$sumM+$inputTable;
?>
<td><?=$inputTable?></td>

<?
}

?>
<td><?=$sum?></td>
</tr>
<?

}

?>