View Single Post
Old 08-26-2009, 07:44 PM   #3 (permalink)
Dave
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
would reset be of any use to you?
Thanks, sketchMedia. I tried reset(), but it does not return the pointer to the first element. Please take a look and see if I've used it wrongly.

Thanks!!

Code:
$c_pettype = 'horse' ; // From user.
$q = "SELECT *
        FROM t_petdata
       WHERE pettype = '$c_pettype' " ;
$q_result = mysql_query($q) or die('no data selected') ;
$q_rowarray = mysql_fetch_assoc($q_result) ;

echo "ELEMENT 1";
echo "<pre>";
print_r($q_rowarray);
echo "</pre>";

echo "using RESET() here..." ;
reset($q_rowarray) ;

$q_rowarray = mysql_fetch_assoc($q_result)
			or die('query failed') ;
echo "SHOULD BE ELEMENT 1 AGAIN";
echo "<pre>";
print_r($q_rowarray);
echo "</pre>";
output:
==================
ELEMENT 1

Array
(
[petpk] => 1
[petname] => unicorn
[pettype] => horse
[petdesc] => spiral horn centered on forehead
[price] => 999.99
)

using RESET() here...SHOULD BE ELEMENT 1 AGAIN

Array
(
[petpk] => 2
[petname] => pegasus
[pettype] => horse
[petdesc] => flying: wings sprouting from back
[price] => 999.99
)
Dave is offline  
Reply With Quote