$sql = "SELECT * FROM `goods` ORDER BY `goods_date` desc"; #送出查詢,回傳查到的資源 $result = mysql_query($sql) or die(mysql_error());//die($sql); #將撈到資料整理成陣列 while ($goods = $result->fetch_assoc()) { $all_goods[] = $goods; } ``` mysqli ``` $sql = "SELECT * FROM `goods` ORDER BY `goods_date` desc"; $result = $mysqli->query($sql) or die($mysqli->connect_error); //fetch_all() MYSQLI_ASSOC(陣列), MYSQLI_NUM(序號) , MYSQLI_BOTH(兩者) $all_goods = $result->fetch_all(MYSQLI_ASSOC); ```
$sql = "SELECT * FROM `goods` ORDER BY `goods_date` desc"; $result = $mysqli->query($sql) or die($mysqli->connect_error); //fetch_all() MYSQLI_ASSOC(陣列), MYSQLI_NUM(序號) , MYSQLI_BOTH(兩者) $all_goods = $result->fetch_all(MYSQLI_ASSOC); ```