/    Sign up×
Community /Pin to ProfileBookmark

Looping through table structure

Morning all,

I’m hoping someone can help me with the final step here. I almost have it except for a formatting issue. Using this loop I can get what I want, almost. I need it to come out looking like this:

Header row
Data Row
Total Row

What I get using this code is:

Header Row
Total Row
Data Row
Data Row…(as many data rows as there are)

I know it’s the structure but I don’t have enough experience to make this work. Any help would be appreciated.

Thanks

Laura

Below is the slimmed down version:

[code]
// first set some basic vars:
$label = “”;
include (“TFWConnect.php”);

//load it all into the associative array
$sql = “”;
$result = mssql_query($sql);
echo “<table border=1>”;

while($row = mssql_fetch_row($result))
{
if($row[0] <> $label)
{
//header row
$label = $row[0];
//totals row

}
//data row
}
echo “</table><br>”;
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@agent_x91Aug 10.2005 — I'm not exactly sure what you're trying to do, but to loop through a table structure all you should need to do it:

[code=php]
echo "<table">;
for($i=0;$i<rows_len;$i++)
{
echo "<tr>";
for($j=0;$j<cols_len;$j++)
{
echo "<td>";
//input the appropriate data from the array here...
echo "</td>";
}
echo "</tr>"
}
echo "</table>";
[/code]
Copy linkTweet thisAlerts:
@agent_x91Aug 10.2005 — The above example assumes that you've loaded the whole list of the table into the array, by the way.
Copy linkTweet thisAlerts:
@lmayer3authorAug 10.2005 — Thanks for the help. I was able to resolve it.
×

Success!

Help @lmayer3 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...