PHP/MySQL Database/mysqli fetch array
function mysql_fetch_array() accomplishes the same result as mysql_fetch_row(), by default it assigns a returned row to an associative array.
array mysql_fetch_array (int result [, result_type])
<?
@mysql_connect("localhost", "root","") or die("Could not connect to MySQL server!");
@mysql_select_db("mydatabase") or die("Could not select database!");
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) :
print $row["id"];
endwhile;
mysql_close();
?>
Using the mysqli_fetch_array() Function
<?php
$link = mysqli_connect("localhost", "username", "password");
if(!$link) {
trigger_error("Could not connect to the database", E_USER_ERROR);
}
mysqli_select_db($link, "myDatabase");
$result = mysqli_query("SELECT first, last FROM members");
if(!$result) {
trigger_error("Could not perform the specified query", E_USER_ERROR);
}
echo "<TABLE><TR><TD>First Name</TD><TD>Last Name</TD></TR>";
while($row = mysqli_fetch_array($result)) {
echo "<TR>";
echo "<TD>{$row["first"]}</TD><TD>{$row["last"]}</TD>";
echo "</TR>";
}
echo "</TABLE>;
mysqli_close($link);
?>