$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = $mysqli->query($query)) {
// get rows with numbered columns
while ($row = $result->fetch_row()) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
$result->close(); // free result set
}
if ($result = $mysqli->query($query)) {
// get rows as associative array - numbered columns and named columns
while ($row = $result->fetch_array(MYSQLI_ASSOC)){
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
$result->close(); // free result set
}
$result->fetch_row() // each row is numbered
echo $row[0];
$result->fetch_array() // each row is numbered and associated with the field name
echo $row[0];
echo $row["FieldName"]; // case sensitive
|