时事通讯错误:为foreach()提供的参数无效

时间:2017-01-04 11:55:26

标签: codeigniter

  

遇到PHP错误

     

严重性:警告

     

消息:为foreach()提供的参数无效

     

文件名:views / editnewsletters.php

     

行号:55

     

回溯:

     

文件:C:\ Program Files   (86)\的EasyPHP-DevServer-14.1VC9 \数据\ localweb \ companygiondaci \应用\视图\ editnewsletters.php   行:55功能:_error_handler

     

文件:C:\ Program Files   (86)\的EasyPHP-DevServer-14.1VC9 \数据\ localweb \ companygiondaci \应用\控制器\ Cpages.php   行:533功能:查看

     

文件:C:\ Program Files   (86)\的EasyPHP-DevServer-14.1VC9 \数据\ localweb \ companygiondaci \的index.php   行:315功能:require_once

视图/ editnewsletters.php

<?php if($newsl) { ?>
                    <?php foreach ($newsl as $newsl_item): ?>

                    <table border="0" style="width: 100%; height: 90px;">
                        <tr>
                            <td>Newsletter Name:</td>
                            <td><input type="text" name="newsletter" value="<?php echo $newsl_item->newsl_name; ?>"></td>
                        </tr>
                        <tr>
                            <td>Newsletter Content:</td>
                            <td><textarea><?php echo $newsl_item->newsl_content; ?></textarea></td>
                        </tr>   
                        <tr>
                            <td></td>
                            <td><input type="submit" class="edit" value="SUBMIT"/></td>
                        </tr>   
                    </table>

                    <?php endforeach; }?>

第55行:

控制器/ cpages.php

public function editnewsletter() { 


    $data['success_message'] = '';  

    $newsl_id = $this->uri->segment(3);

    $data['newsl'] = $this->Mpages->update_newsletter($newsl_id);

    $this->load->view('editnewsletters', $data); 


}

模型/ mpages.php

public function update_newsletter($newsl_id)
{

    $data = array(
        'newsl_name' => $this->input->post('newsl_name'),
        'newsl_date' => $this->input->post('newsl_date'),
        'newsl_content' => $this->input->post('newsl_content')
    );

    $this->db->where('newsl_id', $newsl_id);
    $query = $this->db->update('newsletter', $data);

    return $query;  

}

1 个答案:

答案 0 :(得分:0)

因为您的更新查询返回布尔值。如果您成功更新查询,则 $ query 变量将返回TRUE。如果从表中返回更新的行,则添加此代码。

$this->db->where('id', $newsl_id);
$query = $this->db->get('newsletter');
$data['newsl'] = $query->row();