codeigniter and JSON
Posted
by
ole
on Stack Overflow
See other posts from Stack Overflow
or by ole
Published on 2011-01-12T12:35:46Z
Indexed on
2011/01/12
13:53 UTC
Read the original article
Hit count: 138
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;
}
}
}
© Stack Overflow or respective owner