Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add numbers for each record result

Status
Not open for further replies.

keith23

Technical User
May 26, 2005
97
NL
Hi all i got this query that outputs a number of rows i want print out number next to each record get executed but i do not how to do it since there is no counter. The bold number is where i want to print numbers for each record.For example if the query outputs 3 records it adds numbers from 1-3.I hope some one help me.Thanks
Code:
..........
..........
[b]$query  = "select id,artist,album,title from files where title like '%$s%'";[/b]

while($row = mysql_fetch_assoc($result))
{
  ?>
<tr>
        <td bgcolor="#C0C0C0">[b]numbers&nbsp[/b];</td>
        <td bgcolor="#C0C0C0"><a
        href="javascript:newWindow('./mp3s/myWimpy.php?queryWhere=Id&queryValue=<?=strval( $row['id'] );?>')"><img
        src="./images/Speaker.gif" alt="Listen to this Song"
        border="0" width="16" height="16"
        longdesc="Listen to this Song"></a> <b><?=strval( $row['title'] );?></b>&nbsp;</td>
        <td bgcolor="#C0C0C0"><a
        href="albumsongs.php?albumname=<?=strval( $row['album'] );?>"><?=strval( $row['album'] );?></a>&nbsp;
        </td>
        <td bgcolor="#C0C0C0"><a
        href="albums.php?albumname=<?=strval( $row['artist'] );?>"><?=strval( $row['artist'] );?></a> </td>
        <td bgcolor="#C0C0C0">66&nbsp;</td>
    </tr>
 
Create a counter like:
Code:
[red]$numbers=0;[/red]

then inside the While loop

while($row=...)
{
[red]$numbers++;[/red]
  ?>
<tr>
        <td bgcolor="#C0C0C0">[red]<? echo $numbers; ?>[/red]</td>
        <td bgcolor="#C0C0C0"><a

...

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top