У меня есть 2 таблицы с именем проповедник и проповеди
Поля Проповедника
preacher_id
first_name
last_name
preacher_image
preacher_logo
preacher_bio_brief
category
поля проповедей
sermon_id
preacher_id
sermon_title
sermon_image
audio_file
sermon_description
sort_order
Я хочу отобразить все проповеди каждого проповедника по приказу проповедника first_name. Я получил это правильно, но также получил ошибку ниже
A PHP Error was encountered
Severity: Notice
Message: Undefined index: 1
Filename: home/sermons_view.php
Line Number: 27
метод в контроллере
function index() {
$res = $this->sermon_model->viewAllpreachers();
$this->data['preachers'] = $res;
$this->data['page'] = $this->config->item('APP_template_dir') . 'site/home/ sermons_view';
$this->load->vars($this->data);
$this->load->view($this->_container);
}
Метод в модели
function viewAllpreachers() {
$preacher = array();
$this->db->select('*');
$this->db->from('preacher');
$this->db->order_by('first_name');
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$preacher[$row->preacher_id]['preacher_id'] = $row->preacher_id;
$preacher[$row->preacher_id]['preacher_name'] = $row->first_name . ' ' . $row->last_name;
$preacher[$row->preacher_id]['preacher_image'] = $row->preacher_image;
$preacher[$row->preacher_id]['preacher_bio_brief'] = $row->preacher_bio_brief;
$this->db->select('*');
$this->db->from('sermons');
$this->db->where('preacher_id',$row->preacher_id);
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row1) {
$preacher[$row1->preacher_id][$row1->sermon_id]['sermon_id'] = $row1->sermon_id;
$preacher[$row1->preacher_id][$row1->sermon_id]['preacher_id'] = $row1->preacher_id;
$preacher[$row1->preacher_id][$row1->sermon_id]['sermon_image'] = $row1->sermon_image;
$preacher[$row1->preacher_id][$row1->sermon_id]['sermon_title'] = $row1->sermon_title;
$preacher[$row1->preacher_id][$row1->sermon_id]['audio_file'] = $row1->audio_file;
$preacher[$row1->preacher_id][$row1->sermon_id]['sermon_description'] = $row1->sermon_description;
}
}
}
return $preacher;
}
return false;
}
код в представлении
<code><?php
if ($preachers) {
foreach ($preachers as $val) {
?>
<tr>
<td><img src="<?= base_url(); ?>uploads/<?= $val['preacher_image']; ?>"/></td>
<td colspan="2"><?= $val['preacher_name']; ?></td>
<td colspan="2"><?= $val['preacher_bio_brief']; ?></td>
</tr>
<?
echo '<pre>';
//print_r($val);
echo '
';
foreach ($ val как $ val1) {
?>
uploads/<?= $val1['sermon_image']; ?>" style="width: 60px;height: 60px;"/>
<?= $val1['sermon_title']; ?>
<?= $val1['audio_file']; ?>
<? php $ res = explode ('/', $ val1 ['audio_file']);
if ($ val1 ['audio_file']) {
?>
"> <? = $ res ['1']; ?> <? Php}?>
<? = $ Val1 ['audio_file']; ?>
<?
}
}
}
?>
Я думаю, проблема в результирующем массиве
Я получил это как
Array
(
[21] => Array
(
[preacher_id] => 21
[preacher_name] => Vance Havner
[preacher_image] => profile_image/havner.jpeg
[preacher_bio_brief] => this is for testing
[42] => Array
(
[sermon_id] => 42
[preacher_id] => 21
[sermon_image] => sermon_image/image_81322797345.jpg
[sermon_title] => 3 notes of the devil's tales
[audio_file] => audio_file/Niranja_Mizhiyum1.mp3
[sermon_description] => 3 notes of the devil's tales
)
[41] => Array
(
[sermon_id] => 41
[preacher_id] => 21
[sermon_image] =>
[sermon_title] => The Lordship of Christs
[audio_file] => audio_file/Naladhamayanthi_Kadhayile.mp3
[sermon_description] => the lordship of christ
)
)
)