Jump to content

Archived

This topic is now archived and is closed to further replies.

Zyncmaster2006

Line numbers or row numbers

Recommended Posts

hi can you help me guys. I don't know how to create a script to put a line number on every data I display using mysql_fetch_array. U knw something like this :

1.  Adrian
2.  Manny
3.  Henry

Can you guys provide me a script or a tutorial?? thnx

Share this post


Link to post
Share on other sites
I had to do something similar to what you want to do and found using the id field was not an option so i used an ordered list
It gets all the data from the database and adds 1 to the counter so i get what you want to do.  My OL id is just the style i applied to each name/number

[code]<?php
include_once("includes/connection.php");
$counter = 1;
$q = mysql_query("SELECT id, title FROM news ORDER BY id DESC LIMIT 5");
echo "<OL id=\"blah\">";
while($articles = mysql_fetch_object($q)) {
echo "<LI><a class=\"one\" href=\"/news/".$counter."\">".$articles->title."</a></LI>";
$counter = $counter + 1;
}
echo"</OL>";
?>[/code]

Share this post


Link to post
Share on other sites
You can replace this...

[code=php:0]
$counter = $counter + 1;
[/code]

with...

[code=php:0]
$counter++
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.