Re: Accessing data from next row? (mysql)
| From: | Adam Royle | Date: | Mon, 14 Oct 2002 08:05:18 +0000 |
| Subject: | Re: Accessing data from next row? (mysql) | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-22362@lists.php.net to get a copy of this message | ||
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
adam
Using 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 }