douji1999 2015-10-08 11:22
浏览 30

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

below is my Controller :

<?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');
}

}

And Below is my Model :

<?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;
}

}

?>

And Below is my View :

<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>

Everything works fine actually, until I load title and content from database:
$row-> title . " - ". $row->content."</p>";

I realized that new line in database will not going to convert as <br/> when it get loaded. I mean, let's see this below Data from my SQL :

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

The title and Content are using newline ! Even, when I inspect the element from phpmyadmin, it gave me :
<span>Hadirilah Kajian Wedding Series #6 &nbsp;<br> "Karamnya Sebuah Kapal"</span>

So whats wrong with my script ? Please kindly help. :(

  • 写回答

1条回答 默认 最新

  • donglu7816 2015-10-08 12:09
    关注

    You should use nl2br() function, like this:

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

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)