Page 1 of 1
Automatically Numbering the populated result
Posted: Wed Oct 01, 2003 10:52 am
by sree78
Hi,
I am wondering if it is possible to automatically assign numbers like for an example :-
1. XYX
2. VBG
3. GFT
in a populated result from a database which in this case would be XYX, VBG, GFT. I am fairly new to PHP.. I would really appreciate if you could provide some explanation if you have the answer for my question. In that way I will be able to understand what I am doing. Thanks a lot in advance!!

Posted: Wed Oct 01, 2003 12:08 pm
by volka
html already defines
a numbered list so you don't have to worry about it
Code: Select all
<html>
<head>
<title>an ordered list</title>
</head>
<body>
<ol type="1">
<li>first</li>
<li>second</li>
<li>third</li>
</ol>
</body>
</html>
The bbcode for
- uses (more or less) the same code
- first
- second
- third
added
Posted: Wed Oct 01, 2003 12:12 pm
by Derfel Cadarn
Grr, and while Volka typed that, I wrote the following code:
Code: Select all
<?php
/*
* Name: test
* Author: Derfel
* Created on: 01.10.2003 19:01:34
*/
// Taken from the PHP-Manual
// Connect to the MySQL-database
mysql_connect($host, $user, $password);
// Select the database
mysql_select_db("database");
// Do the query
$result = mysql_query("select user_id from table");
// Set a counter to 1
$i="1";
while ($row = mysql_fetch_array($result)) {
// For each result, present tha counter and the result
echo $i.": ".$row["user_id"]."<br />\n";
// Don't forget to add 1 to the counter for the next result
$i++;
}
// Free the $result (make it empty)
mysql_free_result($result);
?>
But it was fun, though!!
LOL
Posted: Mon Oct 06, 2003 9:16 am
by sree78
Thank you Derfel Cadarn .. your explanation was very clear and it worked... and volka.. I really appreciate your response.... I tried similar code before but since I needed auto numbering for dynamically populated results it did not work.. Once gaain thanks a lot guys.. !!
Posted: Mon Oct 06, 2003 9:18 am
by Nay
Derfel Cadarn wrote:Grr, and while Volka typed that, I wrote the following code.....
heh.........looks like me and Volka are doubling on you!
-Nay
Posted: Mon Oct 06, 2003 9:48 am
by volka
heh.........looks like me and Volka are doubling on you!
instant team work :]
and sree78: of course it does
Code: Select all
<?php
/*
* Name: test
* Author: Derfel
* Created on: 01.10.2003 19:01:34
* Changed by: Volker
*/
// Taken from the PHP-Manual
// Connect to the MySQL-database
mysql_connect($host, $user, $password);
// Select the database
mysql_select_db("database");
// Do the query
$result = mysql_query("select user_id from table");
echo '<ol type="1">';
while ($row = mysql_fetch_array($result))
echo ' <li>', $row['user_id'], '</li>';
echo '</ol>';
mysql_free_result($result);
?>