note 28599 deleted from function.mysql-affected-rows by danbrown

From: Date: Tue, 28 Apr 2009 01:52:18 +0000
Subject: note 28599 deleted from function.mysql-affected-rows by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153885@lists.php.net to get a copy of this message
Note Submitter: adam at NOSPAM dot example dot com ---- 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?>

« previous php.notes (#153885) next »