我是PHP/MySQL的新手,並且是CodeIgniter的新手。 我在許多MySQL表中都有信息。我想用JOIN檢索它,其中表主鍵等於$ variable ...我怎樣才能得到所有沒有主鍵字段的字段???CodeIgniter/PHP/MySQL:通過JOIN檢索數據
我現在正在做的是這樣的(只有兩個表連接在這裏):
function getAll($id) {
$this->db->select('*');
$this->db->from('movies');
$this->db->join('posters', 'movies.id= posters.id');
// WHERE id = $id ... goes here somehow...
$q = $this->db->get();
if ($q->num_rows() == 1) {
$row = $q->row();
$data = array(
'id' => $row->id,
'title' => $row->title,
'year' => $row->year,
'runtime' => $row->runtime,
'plotoutline' => $row->plotoutline,
'poster_url' => $row->poster_url
);
}
$q->free_result();
return $data;
ID(PK),名稱,年份,運行時間和plotoutline從第一表列和poster_url是場從第二張桌子。第二個表格還包含我不想檢索的ID(PK)列,因爲我已經有了。
這樣,我將在兩個表之間的連接,並得到所有的結果嗎?我怎樣才能從我想要獲取數據的行中指定ID?就像'WHERE movies.id = $ id'.. – Jonathan 2009-04-28 13:42:09