note 47520 added to function.mysql-num-rows
| From: | pjoe444 at yahoo dot com | Date: | Thu, 18 Nov 2004 22:24:24 +0000 |
| Subject: | note 47520 added to function.mysql-num-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80727@lists.php.net to get a copy of this message | ||
A pity there seems no way of getting the CURRENT row number that's under iteration in a
typical loop,
such as:
while ($row = mysql_fetch_assoc($result)) { }
After all there is an array of row arrays, as signified by
mysql_num_rows($result):
Say this gives "40 rows" : it would be useful to know when the iteration is on row 39.
The nearest seems to be "data seek":but it connects directly to a
row number eg (from mysql_data_seek page)
for ($i = mysql_num_rows($result) - 1; $i >= 0; $i--) {
if (!mysql_data_seek($result, $i)) {
echo "Cannot seek to row $i: " . mysql_error() . "\n";
continue;
}
= it still wouldn't solve knowing what row number you're on in an ordinary loop.
One reason for this situation is the php fetch (fetch-a-single-row) construction, without any
reasonable FOR loop possibility with row numbers.
Suggestion:
$Rows[$i] possibility where
$i would be the row number
$Rows[$row[], $row[], $row[].....]
0 1 2 etc
-- the excellent retrieval WITHIN a row ( $row[$i] ),
while certainly more important, is not matched by
similar possibilities for rows themselves.
and Count($result) doesnt work of course, $result being a
mere ticket-identifier...
Peter T
----
Manual Page -- http://www.php.net/manual/en/function.mysql-num-rows.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47520
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47520&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47520&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47520&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47520&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47520&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47520&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47520&report=yes
Search -- http://master.php.net/manage/user-notes.php