Suggestion for PHP implementation

From: Date: Mon, 22 Nov 2004 13:49:05 +0000
Subject: Suggestion for PHP implementation
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-26617@lists.php.net to get a copy of this message
Dear webmaster and php revision groups Regarding PhP for use with MySql operations; 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 can be useful for web layout purposes to know when the iteration is on, say, row 20 or row 39. The nearest seems to be "data seek", but it connects directly to a row number, as seen on the 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 doesn't solve using row numbers for different layout purposes within a continuing 'for' loop. One reason for this situation is the PhP language FETCH (fetch-a-single-row) construction, without any reasonable FOR loop possibility with row numbers. * * Suggestion for PhP implementation: * * $Rows[$i] possibility where $i would be the row number $Rows[$row[], $row[], $row[].....] reachable as $Rows[0], $Rows[1], $Row[2] etc -- the excellent retrieval WITHIN a row ( $row[$i] ), while certainly more important, is not matched by similar possibilities for rows themselves. Below: This seems the best workaround to get an 'ordinary' loop going, with possibility of altering output according to row number (eg laying out a schedule) $rowno=mysql_num_rows($result); for ($i=0; $i<mysql_num_rows($result); $i++) { $row = mysql_fetch_assoc($result); print "<div class=\"happening\">"; print "<b>".$row['timeon']."-".$row['timeoff']."</b> ".$row['event']."<br />"; if ($i!=$rowno-1) { print "other-html-within-sched-here</div>"; } else print "end-last-entry-html-here</div>"; } //close loop Thank you for considering this! Best wishes, Peter T ___________________________________________________________ Gesendet von Yahoo! Mail - Jetzt mit 100MB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de

« previous php.mirrors (#26617) next »