我想表列表與sort()函數的陣列排列,但我得到同一種警告 我的代碼如下:PHP:警告:排序()預計參數1是數組,資源給予
<?PHP
require_once("lib/connection.php");
$result = mysql_query("SHOW TABLES FROM `st_db_1`");
sort($result);
foreach ($result as $result){
echo $result ;
}
?>
和我得到的警告是:
Warning: sort() expects parameter 1 to be array, resource given in C:\wamp\www\Copy (4) of st_db_1\test_2.php on line 9
Warning: Invalid argument supplied for foreach() in C:\wamp\www\Copy (4) of st_db_1\test_2.php on line 10
您需要首先[獲取](http://php.net/manual/en/function.msql-fetch-array.php)結果。例如。使用'$ row = mysql_fetch_array($ result):' – 2011-05-29 17:16:10
您需要查找'mysql_query'返回的內容以及'mysql_fetch_assoc'。順便說一下,您需要使用'print_r'而不是'echo'來查看結構。 – 2011-05-29 17:17:24
在你的foreach循環中,你覆蓋了'$ result'變量,這可能不是你想要的。 – judda 2011-05-29 17:26:29