Automatic numbering of table with results on webpage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RotterdamStudents

    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.

    RotterdamStuden ts

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

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

    $result_article s = mysql_query ($str_requete,$ ezine_db) or
    ezine_mysql_die ();

    print ('<table width=75% border=1 bordercolor=#5B 441B
    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_ob ject($result_ar ticles))
    {
    print("
    <tr><td><font face=arial size=1 color=#5B441B>H ere 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>');

    ?>


  • Pedro Graca

    #2
    Re: Automatic numbering of table with results on webpage

    RotterdamStuden ts wrote:[color=blue]
    > 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.[/color]

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

    [color=blue]
    > SCRIPT
    >============== =============== =============== =============== ===========
    > <?php
    > ...[CUT]
    >
    > $str_requete = "SELECT id,name,played, points FROM EkStandings ORDER BY
    > points ASC";
    >
    > $result_article s = mysql_query ($str_requete,$ ezine_db) or
    > ezine_mysql_die ();
    >
    > print ('<table width=75% border=1 bordercolor=#5B 441B
    > 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>
    > ');
    >[/color]

    /* a) and b) */
    $standing_count er = 1;
    [color=blue]
    > while ($articleDb =mysql_fetch_ob ject($result_ar ticles))
    > {[/color]

    /* replace your print
    [color=blue]
    > print("
    > <tr><td><font face=arial size=1 color=#5B441B>H ere 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>
    > ");[/color]

    with another that uses $$standing_coun ter */
    /* c) */
    print("<tr> ... color=#5B441B>$ standing_count</td>...");

    /* d) */
    ++$standing_cou nt;
    [color=blue]
    > }
    >
    > print ('</font></table>');
    >
    > ?>[/color]



    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 :

    Comment

    • Five Cats

      #3
      Re: Automatic numbering of table with results on webpage

      In message <2gh3g2F2ksaoU1 @uni-berlin.de>, Pedro Graca
      <hexkid@hotpop. com> writes[color=blue]
      >RotterdamStude nts wrote:[color=green]
      >> 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.[/color]
      >
      >a) Get a new variable.
      >b) Initialize it to 1.
      >c) Print it to each row and
      >d) Increment it inside the loop.[/color]

      <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

      Comment

      • Five Cats

        #4
        Re: Automatic numbering of table with results on webpage

        In message <c7vtc9$bpe@odb k17.prod.google .com>, PrisonerOfPain
        <hate_me@punkas s.com> writes[color=blue]
        >Why not use a for loop?
        >for ($i = 0; $articleDb =mysql_fetch_ob ject($result_ar ticles); $i++)
        >[/color]
        What happens with this loop when mysql_fetch_obj ect runs out of
        $result_article s to fetch?

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

        // Process each class
        while( $row = mysql_fetch_obj ect (result_article s) )
        {
        $i++;
        // print the stuff
        }

        --
        Five Cats
        Email to: cats_spam at uk2 dot net

        Comment

        • Eric Bohlman

          #5
          Re: Automatic numbering of table with results on webpage

          Five Cats <cats_spam@[127.0.0.1]> wrote in
          news:jqKNAHVxT5 oAFwMV@[127.0.0.1]:
          [color=blue]
          > In message <c7vtc9$bpe@odb k17.prod.google .com>, PrisonerOfPain
          > <hate_me@punkas s.com> writes[color=green]
          >>Why not use a for loop?
          >>for ($i = 0; $articleDb =mysql_fetch_ob ject($result_ar ticles); $i++)
          >>[/color]
          > What happens with this loop when mysql_fetch_obj ect runs out of
          > $result_article s to fetch?[/color]

          It terminates.
          [color=blue]
          >
          > I've always used a while loop:
          > $i = 0;
          >
          > // Process each class
          > while( $row = mysql_fetch_obj ect (result_article s) )
          > {
          > $i++;
          > // print the stuff
          > }
          >[/color]

          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.

          Comment

          • Five Cats

            #6
            Re: Automatic numbering of table with results on webpage

            In message <Xns94E87299BD1 50ebohlmanomsde vcom@130.133.1. 4>, Eric Bohlman
            <ebohlman@earth link.net> writes[color=blue]
            >Five Cats <cats_spam@[127.0.0.1]> wrote in
            >news:jqKNAHVxT 5oAFwMV@[127.0.0.1]:
            >[color=green]
            >> In message <c7vtc9$bpe@odb k17.prod.google .com>, PrisonerOfPain
            >> <hate_me@punkas s.com> writes[color=darkred]
            >>>Why not use a for loop?
            >>>for ($i = 0; $articleDb =mysql_fetch_ob ject($result_ar ticles); $i++)
            >>>[/color]
            >> What happens with this loop when mysql_fetch_obj ect runs out of
            >> $result_article s to fetch?[/color]
            >
            >It terminates.[/color]

            That is what I wasn't sure about.
            [color=blue]
            >[color=green]
            >>
            >> I've always used a while loop:
            >> $i = 0;
            >>
            >> // Process each class
            >> while( $row = mysql_fetch_obj ect (result_article s) )
            >> {
            >> $i++;
            >> // print the stuff
            >> }
            >>[/color]
            >
            >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.[/color]

            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

            Comment

            • RotterdamStudents

              #7
              Re: Automatic numbering of table with results on webpage

              Thank you all very much it works now.


              Comment

              Working...