SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Numbering Table Rows
-
Jun 3, 2009, 20:17 #1
- Join Date
- Jan 2004
- Location
- Seattle
- Posts
- 4,328
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Numbering Table Rows
Imagine a database table that features information on various geographic units, including oceans (oce), continents (con), nations (nat) and dependencies (dep). Suppose I display a table that lists only nations, ranked in order of size (geographic area), with Russia first.
Is there a way to insert numerals to indicate each nation's rank? In other words, the table would look like this...
Code:1. Russia 2. Canada
Is there a PHP function that sequentially numbers table rows?
Thanks.
-
Jun 3, 2009, 21:48 #2
- Join Date
- Nov 2005
- Posts
- 1,191
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Use a counter?
PHP Code:$i = 1;
foreach($countries as $v) {
echo $i;
echo $v;
$i++
}
-
Jun 3, 2009, 21:50 #3
- Join Date
- Jan 2002
- Location
- Australia
- Posts
- 2,634
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$nat = array('Russia', 'Canada', 'New Zealand', 'Monaco', 'Singapore');
$count=0;
foreach($nat as $n) {
$count++;
echo "<tr>
<td>$count</td>
<td>$nat</td>
</tr>\n";
}
-
Jun 3, 2009, 22:12 #4
- Join Date
- Jan 2004
- Location
- Seattle
- Posts
- 4,328
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for the tips. That'll beat adding extra numerical fields in my database table.
Bookmarks