从数据库中重新加载内容,并将新行格式化为</br>在CodeIgniter


Reload a content from database and format New line into </br> in CodeIgniter

下面是我的控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Site extends CI_Controller {
public function __construct() {
    parent::__construct();
    $this->err_msg_model = $this->config->item('err_msg_model');
    $this->err_code = $this->config->item('err_code_model');
    $this->err_code_success = $this->config->item('err_code_success');
    $this->default_reset_pass = $this->config->item('password_default_reset');
    $this->load->helper('form');
}
public function index() {
    $this->load->model('site_model', '', TRUE);
    $this->load->library('pagination');
    $this->load->library('table');
    $limit = 10;
    if ($this->uri->segment(3) === null) {
        $offset = 0;
    } else {
        $offset = $this->uri->segment(3);
    }
    $config['base_url'] = 'http://localhost/gundaling/site/index/';
    $config['total_rows'] = $this->db->get('data')->num_rows();
    $config['per_page'] = $limit;
    $config['num_links'] = 20;
    $queryz = $this->site_model->reportpage2($offset, $limit);
    $result = @json_decode($queryz);
    $code7 = "";
    if ($result != "") {
        $code7 = $result->code;
        $message = $result->message;
        $data['result_select_survey'] = "-";
    } else {
        $data['result_select_survey'] = "";
    }
    if ($queryz->num_rows() > 0) {
        $cupu = $queryz->row();
        $test = $cupu->id;
        echo $test;
        echo "good :)";
    } else {
        echo "bad :(";
    }
    $this->pagination->initialize($config);
    $data['records2'] = $queryz;
    $this->load->view('template-web/vhead');
    $this->load->view('template-web/vheader');
    $this->load->view('template-web/site_view', $data);
    $this->load->view('template-web/vfooter');
}
}

和下面是我的模型:

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Site_model extends CI_Model {
function __construct() {
    parent::__construct();
}
 // Count all record of table "contact_info" in database.
public function reportpage($offset, $limit) {
    $query = "SELECT * FROM data "
            . "LIMIT $offset,$limit";
    log_message('DEBUG', $query);
    if ($this->db->simple_query($query)) {
        $result = $this->db->query($query);
    } else {
        $err_log = $this->db->error();
        $err_log = json_encode($err_log);
        log_message('ERROR', $err_log);
        $result = $err_log;
    }
    return $result;
}
public function reportpage2($offset, $limit) {
    $query = "SELECT * FROM data LIMIT $offset,$limit";
    log_message('DEBUG', $query);
    if ($this->db->simple_query($query)) {
        $result = $this->db->query($query);
    } else {
        $err_log = $this->db->error();
        $err_log = json_encode($err_log);
        log_message('ERROR', $err_log);
        $result = $err_log;
    }
    return $result;
}
}
?>

和下面是我的观点:

<div class="c-layout-page">
<!-- BEGIN: PAGE CONTENT -->
<div id="container">
    <h1>Super Pagination with Code Igniter</h1>
    <?php foreach($records2->result() as $row){
        echo "<p>".$row->id . " : ". 
             $row-> title . " - ". $row->content."</p>";
    } 
    ?>
    <?php echo $this->pagination->create_links(); ?>
</div>
</div>

实际上一切都很好,直到我从数据库加载标题和内容:
$row-> title . " - ". $row->content."</p>";

我意识到数据库中的新行在加载时不会转换为<br/>。我的意思是,让我们看看下面的数据从我的SQL:

 |id  | title                            | content
 |1   | Hadirilah                        | Bismillahirrohmanirrohim
 |    | Kajian Wedding Series #6         | Assalamu`allaikum 
 |    | "Karamnya Sebuah Kapal"          | warohmatullahi wabarokatuh

标题和内容使用换行符!甚至,当我从phpmyadmin中检查元素时,它给了我:
<span>Hadirilah Kajian Wedding Series #6 &nbsp;<br> "Karamnya Sebuah Kapal"</span>

我的脚本有什么问题?请帮忙。(

应该使用nl2br()函数,如下所示:

echo "<p>".$row->id . " : ". $row-> title . " - ". nl2br($row->content)."</p>";