I am using CodeIgniter, basically I have a table which has dummy data, and I am returning this data using jQuery.
I do this by:
Controller:
class Notifications extends CI_Controller{
function getAlerts(){
$query = $this->db->query("SELECT ID, subject, message, readMessage FROM data WHERE readMessage = 0");
$result = $query->num_rows();
if($result > 0){
return $result;
echo $result;
}
}
Header Script:
<script type="text/javascript">
$(function() {
getMessageCount1();
});
function getMessageCount1() {
$('div#alertsfrommydb').load('<?php echo base_url(); ?>notifications/getAlerts').fadeIn();
setTimeout("getMessageCount1()", 10000);
}
</script>
and the view as such:
<div id="alertsfrommydb">
</div>
I have a method which is called showAlerts() in the same controller which prints a table and shows my messages refreshing every 10 seconds, and this works perfectly fine using above approach.
In addition I have a method called notifications.php and I load this in my controller, which then allows me to simply in my view type:
print_r($this->notifications->getAlerts());
And the query shows my results fine which is '6' meaning I have 6 unread messages.
So my argument is, the query is working, so why will it not work using the jQuery approach.
Although my query works, I have a gut feeling there is something not right about it lol, hope someone can help.
Thanks