Re: Accessing data from next row? (mysql)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux