Re: Accessing data from next row? (mysql)
| From: | Adam Royle | Date: | Mon, 14 Oct 2002 08:38:31 +0000 |
| Subject: | Re: Accessing data from next row? (mysql) | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-22365@lists.php.net to get a copy of this message | ||
Also, if you're not sure how to get the values from $arrThisRow / $arrNextRow:
echo $arrThisRow['columnName'];
or $arrData[$i]['columnName'] if you want to access it manually without the other two arrays
adam
On Monday, October 14, 2002, at 06:05 PM, Adam Royle wrote:
Create an array and go through the array as needed. Here is some code from one of my db functions: $DB_RESULT = @mysql_query($sql) or die("Error executing query: " . mysql_error()); // create an empty array to fill with data $arrData = array(); $rowCount = 0; while ($r = mysql_fetch_array($DB_RESULT, MYSQL_ASSOC)){ foreach ($r as $key => $value){ $arrData[$rowCount][$key] = $value; } $rowCount++; } then simply instead of your code: while($array = mysql_fetch_array($result)){ use this: for ($i=0;$i<count($arrData);$i++){ $arrThisRow = $arrData[$i]; $arrNextRow = $arrData[$i+1]; } obviously, if you are trying to access a variable which index does not exist, you will need to implement some sort of error checking, etc adamUsing mysql, how do I access the data of the next row using code something like this: $result = mysql_query("select column from table where whatever='whatever'"); while($array = mysql_fetch_array($result)){ //Whatever }