开发者

codeigniter and JSON

Hello all i having a problem that it only get 1 value in my database and its my title and i want to show content and username from the same table to.

here is my JSON kode

      <script type="text/javascript">
    $.getJSON(
         'ajax/forumThreads', 
       开发者_如何学编程  function(data) {
             alert(data[0].overskrift);
             alert(data[0].indhold);
         }
     );
  </script>

my controller

    <?php
class ajax extends Controller
{

 function forumThreads() {

     $this->load->model('ajax_model');
     $data['forum_list'] = $this->ajax_model->forumList();

     if ($data['forum_list'] !== false) {
         echo json_encode($data['forum_list']);
     }
 }

}

my model fle

    <?php
class ajax_model extends Model
{

 function forumList()
 {
     $this->db->select('overskrift', 'indhold', 'brugernavn', 'dato');
     $this->db->order_by('id', 'desc');
  $this->db->limit(5);
     $forum_list = $this->db->get('forum_traad');

     if($forum_list->num_rows() > 0)
     {
         return $forum_list->result_array();
     } else {
         return false;
     }
 }

}


Try

$this->db->select('overskrift, indhold, brugernavn, dato');

The select method takes two arguments: the first one being the selected fields as string, the second a boolean, which – if set to false – will prevent CI from surrounding field or table names with back ticks. (Thanks @predrag.music).

OT: That's one of the things that always bothered me a little when it comes to CI's approach: The "Active Record" class is nothing more but a query string factory, but makes itself look like more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜