473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Automatic numbering of table with results on webpage

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
6 2660
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
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
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
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
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
Thank you all very much it works now.
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: fatih kayaalp | last post by:
Hi, i have imported an access database into sqlserver 2000. In access, i have some table fields which were using automatic number as datatype. But i see that there is not a datatype in sqlserver...
10
by: john T | last post by:
Is there anyway to vertically center a html table using css in such a way it does not alter the html table. When I tryied it just screws up.
3
by: Chris | last post by:
Before I started to create table, etc to track unique form field record number assigments I thought I'd check to see if there is now a better way to do this in .NET. I have a parent form (table)...
2
by: Patrick Olurotimi Ige | last post by:
When i run the code below with stored proc :- I get only the first table results :-"templates" even if i fill the dataset with another table for example category,pages etc.. Any ideas? ...
54
by: MLH | last post by:
I use A97 and do not always insert line numbers while writing procedures. I find it necessary to go back and add them later to aid in debugging. Nearly 3 years ago, something was mentioned in...
1
by: Michael Doubez | last post by:
Hello, I want to mix in the same document Parts that have automatically numbered sections and parts which section are not numbered. Is there any out of the box way to locally suppress the...
1
by: Dan Somdahl | last post by:
Hi, I am new to ASP but have what should be a fairly simple task that I can't figure out. I need to parse a string from a single, semi-colon delimited, 60 character field (el_text) in a recordset...
1
by: Rajen | last post by:
I've a automatic configuration proxy (http://xxx.xxx.xxx.xxx/xyz.pac) which I use in the Internet explorer Lan Settings to access the net. How do I read a webpage by specifying this proxy in my...
0
by: cephal0n | last post by:
Hi All! I have two table tblHome1, contains all the unique PinNo and tblHome2 contains a duplicated PinNo and description. I put an automatic numbering (ProdID) and set it as my index. What I want...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.