note 28599 added to function.mysql-affected-rows
| From: | adam at NOSPAM dot example dot com | Date: | Fri, 17 Jan 2003 17:34:40 +0000 |
| Subject: | note 28599 added to function.mysql-affected-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42288@lists.php.net to get a copy of this message | ||
using PHP/MySql -There is an alternate way to get the rows returned -
for non-critical use i suppose--due to its oversimplified approach.
You can simply intialize a variable to the integer value of 0, and then, inside of the
"while" loop that returns the rows
of your query, you increment that variable and then print out the final value of that variable
outside of that "while" loop.
Or, you could print the variable within each iteration if you want to give each row returned [ as in
a chart where you
need to provide line numbers ]
//code:
$sql = "SELECT * FROM YourTable
ORDER BY Last_Name";
$result = @mysql_query($sql, $connection) or die("Could not execute query.");
$i = 0; // we will use variable $i as a returned row counter.
while ($row = mysql_fetch_array($result)) {
$First_Name = $row['First_Name'];
$Last_Name = $row['Last_Name'];
$num_rows = mysql_num_rows($result);
$i++;
//To show the rows number by number
echo "Member no. $i $First_Name $Last_Name < br >";
// the < br > is an actual HTML line break
// which is not allowed on posting these notes,
// to use it, close up the spaces between the < and the >
// above echo statement will produce the results below if 3 rows were returned:
// Member no. 1 John Jones
// Member no. 2 Mary Smith
// Member no. 3 Nancy Steffan
}
echo "$i Rows Returned from query.";
// above statement will produce:
// 3 Rows Returned from query.
Hope this helps-- again,
this is a simplified approach.
take care;
<?adam?>
--
http://www.php.net/manual/en/function.mysql-affected-rows.php
http://master.php.net/manage/user-notes.php?action=edit+28599
http://master.php.net/manage/user-notes.php?action=delete+28599
http://master.php.net/manage/user-notes.php?action=reject+28599