好吧,我執行這個雙重結果
$table = get_personel_table(1);
function get_personel_table($id)
{
global $connection;
$query = "SELECT * ";
$query .= "FROM employees ";
$query .= "WHERE id=" . $id . " ";
$query .= "ORDER BY id ASC";
$query_result = mysql_query($query , $connection);
confirm_query($query_result);
$query_result_array = mysql_fetch_array($query_result);
return $query_result_array; // returns associative array!;
}
而且我的foreach
foreach($table as $table_var)
{
echo "<td>" . $table_var . "</td>";
}
,並通過這樣做,我得到的雙輸出...「1 1 1 1喬丹約旦9108121544 9108121544 testemail子testemail子testAddress testAddress testCounty testCounty」
這下面是print_r的結果
Array
(
[0] => 1
[id] => 1
[1] => 1
[department_id] => 1
[2] => jordan
[name] => jordan
[3] => 9108121544
[EGN] => 9108121544
[4] => testEmail
[email] => testEmail
[5] => testAddress
[address] => testAddress
[6] => testCounty
[country] => testCounty
)
我在數據庫中的信息是id => 1,department_id => 1,依此類推...我的問題是爲什麼我得到雙重反饋(我不知道如何調用它), 0 = id,1 = department_id,2 =名稱等。
當我做foreach(...)我得到的一切都翻了一番。
使用'mysql_fetch_array($ result,MYSQL_ASSOC)'。默認情況下,它將數字和列名作爲索引返回。我傾向於推薦'mysql_fetch_assoc()'來避免這個問題。 – 2012-03-04 16:51:45
可能重複的[mysql_fetch_array和只有字符串數組鍵](http://stackoverflow.com/questions/7440479/mysql-fetch-array-and-only-string-array-keys) – 2012-03-04 16:52:57