PHP/MySQL Database/mysqli fetch array

Материал из Web эксперт
Перейти к: навигация, поиск

function mysql_fetch_array() accomplishes the same result as mysql_fetch_row(), by default it assigns a returned row to an associative array.

   <source lang="html4strict">

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(); ?>

 </source>
   
  


Using the mysqli_fetch_array() Function

   <source lang="html4strict">

<?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 "";
    while($row = mysqli_fetch_array($result)) {
echo ""; echo ""; echo ""; } echo "
First NameLast Name
{$row["first"]}{$row["last"]}
;
    mysqli_close($link);

?>

 </source>