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: " . 

        // 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;

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


> 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
> }

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to