1.array mysql_fetch_assoc ( resource $result
) gets a row from the result set as an associative array
Description
returns an associative array of corresponding result sets, and continues to move the internal data pointer.
Parameters:result
The result set of the resource type. This result set is from a call to mysql_query ().
Instance:
<?PHP$conn= Mysql_connect ("localhost","Mysql_user","Mysql_password" ); if(!$conn) {echo"Unable to connect to DB:".mysql_error (); Exit;} if(! mysql_select_db ("Mydbname") {echo"Unable to select Mydbname:".mysql_error (); Exit;} $sql="SELECT ID as userid, fullname, userstatus from sometable WHERE userstatus = 1" ; $result= mysql_query ($sql ); if(!$result) {echo"Could not successfully run query ($sql) from DB:".mysql_error (); Exit;} if(Mysql_num_rows ($result) ==0) {echo"No rows found, nothing-to-print so am exiting" ; Exit;} // whileA row of dataexists, put that row in$rowAs an associative arrayNote:IfYou're expecting just one row, no need to use a loop//note:if your put extract ($row); inside the following loop, you'llThen create$userid,$fullname, and$userstatus while($row= Mysql_fetch_assoc ($result) {echo$row["userid" ]; Echo$row["FullName" ]; Echo$row["UserStatus" ];} Mysql_free_result ($result ); ?>
MySQL function collection in PHP