php loop problem

  • smiledrops
  • Student
  • Student
  • User avatar
  • Joined: Jul 07, 2005
  • Posts: 66
  • Loc: pakistan
  • Status: Offline

Post May 30th, 2008, 8:04 am

HI
i want to dispaly the query result as attached file, i spent about 5 hours for it but fails.

i get the following format ( also in attached file ) can any body help me to sort this out the code i used as following:

the code i have used as:

<table cellpadding="0" cellspacing="1" style="font: normal 11px Verdana, Arial;" bgcolor="#FFFFFF" align="center">

<?php


$outPut = ""; $ii = 0;

$idForm = 26;
$idUser = 19;

$connect = dbConnect();

$sql_dated = dbQuery("select distinct(usrRatingAdded) from pg3_users_forms where frmID = '$idForm' and usrID = '$idUser' and usrRatingAdded >= '2008-05-20' and usrRatingAdded <= '2008-05-30' order by usrRatingAdded asc ", $connect);
while($res_dated = dbFetchArray($sql_dated) )
{
$first = $ff = true;
$dated = @dated( $res_dated['usrRatingAdded'], '-', ' ' );

$outPut .= "<tr bgcolor=\"#CCCCCC\"><td colspan=\"10\" style=\"padding: 3px;text-align:center;\"><b>{$dated}</b></td></tr>";
$sql_client = dbQuery("select distinct(clientID), fldID, usrAchieved from pg3_users_forms where frmID = '$idForm' and usrID = '$idUser' and usrRatingAdded = '{$res_dated['usrRatingAdded']}' ", $connect);
while( $res_client = dbFetchArray($sql_client) )
{
$client = dbaseTitle( $res_client['clientID'] );
$fieldID = $res_client['fldID'];

if( $ff )
{
$ff = false;
$outPut .= "<tr bgcolor=\"#F7F7F7\" valign=\"top\"><td style=\"padding: 5px; border: 1px solid #AAAAAA;\"><b>Client Name</b></td>";

$sql_field = dbQuery("select fld_title from pg3_forms_fields where frmID = '$idForm' order by fldID asc", $connect);
while( $res_field = dbFetchArray($sql_field) )
$outPut .= "<td style=\"padding: 5px; border: 1px solid #AAAAAA;\"><b>{$res_field['fld_title']}</b></td>";
$outPut .= "</tr>";
}

$sql_report = dbQuery("select clientID, usrAchieved, usrComments from pg3_users_forms where clientID='{$res_client['clientID']}' and frmID='$idForm' and usrRatingAdded >= '2008-5-20' and usrRatingAdded <= '2008-5-30' ", $connect);
$numRows = dbNumRows($sql_report);

if( $first )
{
$first = false;
$outPut .= "<tr bgcolor=\"#F7F7F7\" valign=\"top\"><td style=\"padding: 5px; border: 1px solid #AAAAAA;\"><b>{$client}</b></td>";
while( $res_report = dbFetchArray($sql_report) )
$outPut .= "<td style=\"padding: 5px; border: 1px solid #AAAAAA;\"><b>{$res_report['usrAchieved']}</b></td>";
$outPut .= "</tr>";
}
}
}

echo $outPut;
?>
</table>
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 30th, 2008, 8:04 am

  • Bogey
  • PHP Ninja
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7337
  • Loc: Imagination
  • Status: Offline

Post May 30th, 2008, 1:15 pm

Are you using mysql_fetch_array(); or mysql_fetch_assoc(); to retrieve data from MySQL.

If you want to retrieve associative arrays using mysql_fetch_assoc(); you could use

mysql_fetch_array($query, ASSOC);

or better yet

mysql_fetch_assoc();

If you use mysql_fetch_array(); with no assoc than to retrieve data it would look something like...

$name = $row[1];

--

So you want to create a page using PHP with the results in it? I'm probably not understanding you but are you trying to put your results into like a *.pdf file?
Learn PHP

Apocalyptica - I Don't Care (Listen to this most awesome song ever!)
  • sevster
  • Bronze Member
  • Bronze Member
  • User avatar
  • Joined: Jun 17, 2005
  • Posts: 518
  • Status: Offline

Post May 30th, 2008, 2:49 pm

Also take a look at your multiple nested while loops. You have some parenthetical issues there, not to mention the logical/complexity issues.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 380 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2010 Unmelted, LLC. Driven by phpBB © 2010 phpBB Group.