这是我的查询:
$query = $this->db->query(' SELECT archives.id, archives.signature, type_of_source.description, media_type.description, origin.description FROM archives, type_of_source, media_type, origin WHERE archives.type_of_source_id = type_of_source.id AND type_of_source.media_type_id = media_type.id AND archives.origin_id = origin.id ORDER BY archives.id ASC ');
但是如何输出结果呢?这有效,但只获得最后的描述(origin.description):
foreach ($query->result_array() as $row) { echo $row['description']; }
这不起作用:
foreach ($query->result_array() as $row) { echo $row['type_of_source.description']; }
或者我应该重命名列(例如type_of_source_description)?
这实际上与CodeIgniter关系不大,而且mysql_fetch_assoc如何提供查询结果.解决方案是您应该使用"AS"重命名查询中的列,例如
select type_of_source.description as type_of_source_description, origin.descripotion as origin_descripotion from ....