By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,665 Members | 1,900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,665 IT Pros & Developers. It's quick & easy.

Automatic numbering of table with results on webpage

P: n/a
Hello group,

the script on this page i use to show the standings in a league. It is shown
in a table on my webpage. But I don't know how to number the rows so that
the first row is number 1 the second 2 and so on, so that the numbers are
equal to the standings.

Who has a solution for this.

Thnx.

RotterdamStudents

SCRIPT
================================================== ====================
<?php
....[CUT]

$str_requete = "SELECT id,name,played,points FROM EkStandings ORDER BY
points ASC";

$result_articles = mysql_query ($str_requete,$ezine_db) or
ezine_mysql_die();

print ('<table width=75% border=1 bordercolor=#5B441B
cellspacing=0><font face=arial size=2><B>
<tr><td><font face=arial size=2 color=#957745><B>Position:</B></td>
<td><font face=arial size=2 color=#957745><B>Name:</B></td>
<td><font face=arial size=2 color=#957745><B>Played:</B></td>
<td><font face=arial size=2 color=#957745><B>Points:</B></td>
');

while ($articleDb =mysql_fetch_object($result_articles))
{
print("
<tr><td><font face=arial size=1 color=#5B441B>Here i want the position
numbers</td>
<d><font face=arial size=1 color=#5B441B>$articleDb->name</td>
<td><font face=arial size=1 color=#5B441B>$articleDb->played</td>
<td><font face=arial size=1 color=#5B441B><b>$articleDb->points</td>
</tr>
");
}

print ('</font></table>');

?>
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
RotterdamStudents wrote:
the script on this page i use to show the standings in a league. It is shown
in a table on my webpage. But I don't know how to number the rows so that
the first row is number 1 the second 2 and so on, so that the numbers are
equal to the standings.
a) Get a new variable.
b) Initialize it to 1.
c) Print it to each row and
d) Increment it inside the loop.

SCRIPT
================================================= =====================
<?php
...[CUT]

$str_requete = "SELECT id,name,played,points FROM EkStandings ORDER BY
points ASC";

$result_articles = mysql_query ($str_requete,$ezine_db) or
ezine_mysql_die();

print ('<table width=75% border=1 bordercolor=#5B441B
cellspacing=0><font face=arial size=2><B>
<tr><td><font face=arial size=2 color=#957745><B>Position:</B></td>
<td><font face=arial size=2 color=#957745><B>Name:</B></td>
<td><font face=arial size=2 color=#957745><B>Played:</B></td>
<td><font face=arial size=2 color=#957745><B>Points:</B></td>
');

/* a) and b) */
$standing_counter = 1;
while ($articleDb =mysql_fetch_object($result_articles))
{
/* replace your print
print("
<tr><td><font face=arial size=1 color=#5B441B>Here i want the position
numbers</td>
<d><font face=arial size=1 color=#5B441B>$articleDb->name</td>
<td><font face=arial size=1 color=#5B441B>$articleDb->played</td>
<td><font face=arial size=1 color=#5B441B><b>$articleDb->points</td>
</tr>
");
with another that uses $$standing_counter */
/* c) */
print("<tr> ... color=#5B441B>$standing_count</td>...");

/* d) */
++$standing_count;
}

print ('</font></table>');

?>


Happy Coding :-)

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

P: n/a
In message <2g************@uni-berlin.de>, Pedro Graca
<he****@hotpop.com> writes
RotterdamStudents wrote:
the script on this page i use to show the standings in a league. It is shown
in a table on my webpage. But I don't know how to number the rows so that
the first row is number 1 the second 2 and so on, so that the numbers are
equal to the standings.


a) Get a new variable.
b) Initialize it to 1.
c) Print it to each row and
d) Increment it inside the loop.


<snipped>

At the end of the loop, the method above will leave the variable set to
1 more than the number of rows printed. If that matters:

a) get a new variable
b) initialize it to 0
c) increment it inside the loop
d) print the row

--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #3

P: n/a
In message <c7********@odbk17.prod.google.com>, PrisonerOfPain
<ha*****@punkass.com> writes
Why not use a for loop?
for ($i = 0; $articleDb =mysql_fetch_object($result_articles); $i++)

What happens with this loop when mysql_fetch_object runs out of
$result_articles to fetch?

I've always used a while loop:
$i = 0;

// Process each class
while( $row = mysql_fetch_object (result_articles) )
{
$i++;
// print the stuff
}

--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #4

P: n/a
Five Cats <ca*******@[127.0.0.1]> wrote in
news:jq**************@[127.0.0.1]:
In message <c7********@odbk17.prod.google.com>, PrisonerOfPain
<ha*****@punkass.com> writes
Why not use a for loop?
for ($i = 0; $articleDb =mysql_fetch_object($result_articles); $i++)
What happens with this loop when mysql_fetch_object runs out of
$result_articles to fetch?


It terminates.

I've always used a while loop:
$i = 0;

// Process each class
while( $row = mysql_fetch_object (result_articles) )
{
$i++;
// print the stuff
}


The only difference between that structure and the OP's for loop is that
the "print the stuff" code sees $i starting from one rather than zero.
Jul 17 '05 #5

P: n/a
In message <Xn*******************************@130.133.1.4>, Eric Bohlman
<eb******@earthlink.net> writes
Five Cats <ca*******@[127.0.0.1]> wrote in
news:jq**************@[127.0.0.1]:
In message <c7********@odbk17.prod.google.com>, PrisonerOfPain
<ha*****@punkass.com> writes
Why not use a for loop?
for ($i = 0; $articleDb =mysql_fetch_object($result_articles); $i++)
What happens with this loop when mysql_fetch_object runs out of
$result_articles to fetch?


It terminates.


That is what I wasn't sure about.

I've always used a while loop:
$i = 0;

// Process each class
while( $row = mysql_fetch_object (result_articles) )
{
$i++;
// print the stuff
}


The only difference between that structure and the OP's for loop is that
the "print the stuff" code sees $i starting from one rather than zero.


I think that was what the OP wanted. BTW the real OP doesn't appear
here - they've got snipped somewhere along the line!

--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #6

P: n/a
Thank you all very much it works now.
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.