我是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