PHP connection MySQL I have already written the article, this article is mainly about the query from the MySQL results after the output of the problem.
One: Mysqli_fetch_row ();
Query Result: Array ([0]=> Xiao Wang)
Inquire:
while ($row = Mysqli_fetch_assoc ($result)) {$memberlist = $row [0];} End while ()
II: Mysqli_fetch_assos ();
Query Result: Array ([name]=> Xiao Wang)
Inquire:
while ($row = Mysqli_fetch_assoc ($result)) {$memberlist = $row [' Memberlist '];} End while ()
Third, Mysqli_fetch_array ();
Query Result: Array ([0]=> Xiao Wang [name]=> Xiao Wang)
Inquire:
while ($row = Mysqli_fetch_assoc ($result)) {$memberlist = $row [' memberlist ']; $memberlist = $row [0];} End while ()
Iv. Fetch_array ();
Query Result: Array ([0]=> Xiao Wang [name]=> Xiao Wang)
Inquire:
$sql = "SELECT * from user"; $result = $conn->query ($sql); if ($result) { if ($result->num_rows>0) {while ($rows = $result->fetch_array ()) { Print_r ($rows); echo "<br>rows[' ID ']:". $rows [' id ']; echo "<br>rows[' name ']:". $rows [' name ']; echo "<br>rows[' pwd ']:". $rows [' pwd ']; } End while () }else{ echo "<BR> query result is empty! "; } End if () }else{ echo "<BR> query failed! "; } End if ()
From the above can be seen different function output format is not the same, Mysqli_fetch_row () is returned by the number index, Mysqli_fetch_assos () is indexed by the keyword, and Mysqli_fetch_array () and Fetch_array () the use of numbers also uses keywords to index.
PHP Output mysqli Query results