【问题标题】:Newsletter error: Invalid argument supplied for foreach()通讯错误:为 foreach() 提供的参数无效
【发布时间】:2017-01-04 11:55:25
【问题描述】:

遇到了 PHP 错误

严重性:警告

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

文件名:views/editnewsletters.php

行号:55

回溯:

文件:C:\Program 文件 (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\companygiondaci\application\views\editnewsletters.php 行:55 函数:_error_handler

文件:C:\Program 文件 (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\companygiondaci\application\controllers\Cpages.php 行:533 功能:查看

文件:C:\Program 文件 (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\companygiondaci\index.php 行:315 功能:require_once

views/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 行:


controllers/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); 


}

models/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;  

}

【问题讨论】:

  • 从您提供的代码看来,您正在返回更新后的查询结果,我怀疑其中没有数据集行 (ie)result()...您可以在 mpages 中回显 $query并显示 o/p
  • 也许 echo $query 是 1。我在页面之间看到一个“1”。

标签: codeigniter


【解决方案1】:

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

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

【讨论】:

  • 返回什么?
  • 返回布尔值
  • 怎么样?比如 return $data['newsl']; ?
猜你喜欢
  • 2013-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多