我需要选择一个整列。 所以我的问题是如何获得一整列?mysql选择整列或循环遍历所有ID
$query = "SELECT * ";
$query .= "FROM employees ";
$query .= "WHERE id=*";
$query .= "ORDER BY id ASC ";
我试过ID = *,但没有运气... 我的目标是通过循环所有的ID,但有些可能会丢失,所以我想通我把它们放在一个数字或关联数组和使用的foreach。如果有更好的方法,请分享。
编辑:
function get_all_ids()
{
global $connection;
$query = "SELECT * ";
$query .= "FROM employees ";
$query_result = mysql_query ($query , $connection);
confirm_query($query_result);
$query_result_array = mysql_fetch_assoc($query_result);
return $query_result_array;
}
我使用它来打印阵列
$all_id = get_all_ids();
// preparing the table;
echo "<pre>";
print_r($table);
print_r($all_id);
echo "</pre>";
,这是阵列
Array
(
[id] => 1
[department_id] => 1
[name] => jordan
[EGN] => 9108121544
[email] => testEmail
[address] => testAddress
[country] => testCounty
)
没有运气,那只是给了我第一排。 – Jordashiro 2012-03-05 17:06:44
你确定数据库中有多行吗? – prodigitalson 2012-03-05 17:07:32
是的,我会在一秒内更新我的问题。 – Jordashiro 2012-03-05 17:07:58