Tuesday, 21 February 2012

Q: how many array in php and also tell different each type array?


1.  mysql_fetch_array
2.  mysql_fetch_assoc
3.  mysql_fetch_object
4.  mysql_fetch_row
5.  mysql_fetch_field
 mysql_fetch_arrayFetch a result row as an associative array, a numeric array, or both
while ($row mysql_fetch_array($resultMYSQL_NUM)) {
    
printf("ID: %s  Name: %s"$row[0], $row[1]);  
}
while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {
    
printf("ID: %s  Name: %s"$row["id"], $row["name"]);
}
mysql_fetch_assocFetch a result row as an associative array
while ($row mysql_fetch_assoc($result)) {
    echo 
$row["userid"];
    echo 
$row["fullname"];
    echo 
$row["userstatus"];
}
mysql_fetch_fieldGet column information from a result and return as an object

$result mysql_query('select * from table');
    $meta mysql_fetch_field($result);
    
blob:         $meta->blob
max_length:   
$meta->max_length
multiple_key: 
$meta->multiple_key
}
mysql_fetch_objectFetch a result row as an object
$result mysql_query("select * from mytable");
while (
$row mysql_fetch_object($result)) {
    echo 
$row->user_id;
    echo 
$row->fullname;
}
mysql_fetch_rowGet a result row as an enumerated array
$result mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!
$result) {
    echo 
'Could not run query: ' mysql_error();
    exit;
}
$row mysql_fetch_row($result);
echo 
$row[0]; // 42
echo $row[1]; // the email value

No comments:

Post a Comment