-1
我在codeigniter中遇到UNION查詢問題。它給出的輸出,但名稱是相同的數組中的兩列。Codeigniter UNION查詢問題
$sql = "SELECT firstname FROM user_profile WHERE user_id ='".$id."'
UNION SELECT email FROM user WHERE id='".$id."'";
$data = $this->db->query($sql);
print_r($data->result());
,這是輸出:
Array
(
[0] => stdClass Object
(
[firstname] => Dimpy
)
[1] => stdClass Object
(
[firstname] => [email protected]
)
)
請通過[PDO](http://php.net/pdo)或[PDO](http://php.net/pdo)學習如何使用[** prepared statements **](https://www.youtube.com/watch?v=nLinqtCfhKY)庫MySQLi](http://php.net/mysqli)。 –
Teresko,他使用codeigniter。開始將自己的MySQL驅動程序加入其中並不實際。 不過Dimple,你應該確定你使用的數據沒有被瀏覽器解析。 – andershagbard
當你需要分開的列使用連接而不是聯合 –