foreach ($timetable as $row) {
echo $row->course_name;
}
我的查询是:
public function select_timetable() {
$this->db->select('sequence_num, topic, courses_specific_id, courses_common.course_name,
courses_specific.course_place, courses_common.courses_common_id, timetable.timetable_id');
$this->db->from('timetable');
$this->db->join('courses_common', 'courses_common.courses_common_id=timetable.courses_common_id');
$this->db->join('courses_specific', 'courses_specific.courses_common_id=courses_common.courses_common_id');
$this->db->where('courses_specific_id', $this->input->post('courses_specific_id'));
$result=$this->db->get();
return $result->result();
}
var_dump($timetable[0])
的结果是:
object(stdClass)#27 (7) {
["sequence_num"]=> string(1) "1"
["topic"]=> string(10) "HTML tags "
["courses_specific_id"]=> string(1) "1"
["course_name"]=> string(4) "HTML"
["course_place"]=> string(6) "Center"
["courses_common_id"]=> string(1) "1"
["timetable_id"]=> string(1) "1"
}
HTMLobject(stdClass)#27 (7) {
["sequence_num"]=> string(1) "1"
["topic"]=> string(10) "HTML tags "
["courses_specific_id"]=> string(1) "1"
["course_name"]=> string(4) "HTML"
["course_place"]=> string(6) "Center"
["courses_common_id"]=> string(1) "1"
["timetable_id"]=> string(1) "1"
}
HTMLobject(stdClass)#27 (7) {
["sequence_num"]=> string(1) "1"
["topic"]=> string(10) "HTML tags "
["courses_specific_id"]=> string(1) "1"
["course_name"]=> string(4) "HTML" ["course_place"]=> string(6) "Center" ["courses_common_id"]=> string(1) "1" ["timetable_id"]=> string(1) "1" } HTML
答案 0 :(得分:2)
要访问结果,您必须执行以下操作:
<?php
foreach ($timetable->result() as $row)
{
echo $row->course_name;
}
?>
如果您只想显示一行,则需要执行以下操作:
if ($timetable->num_rows() > 0)
{
$row = $timetable->row_array();
echo $row['course_name'];
}
您还可以浏览不同的行,例如:
$row = $timetable->first_row()
$row = $timetable->last_row()
$row = $timetable->next_row()
$row = $timetable->previous_row()