CodeIgniter Forums
Simple facebook notification can't run ... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Simple facebook notification can't run ... (/thread-53238.html)



Simple facebook notification can't run ... - El Forum - 07-16-2012

[eluser]beben[/eluser]
i've got tutorial that create simple facebook notification in PHP,, just check that the data in database have been update or not..

So, i've been download the code and i want to use it in codeigniter,, i've made controller and the model,, and i also use ajax...

This is the code..

Model
Code:
class Notification_model extends Model {

function Notification_model() {
    parent::Model();
}

function cek_pesan()
    {
        $id_instansi = $this->session->userdata('id_instansi');

        $SQL = "SELECT id_sm FROM view_arus_surat_internal WHERE id_tujuan='".$id_instansi."'
                AND status_terima1='Belum Diterima'";

        $Q = count($this->db->query($SQL));

        return $Q;
    }  
}

Contoller

Code:
function cekPesan()
{
    $this->load->model('notification_model');

    $data['num'] = $this->notification_model->cek_pesan();

    $this->load->view('notification/notification',$data);

}

function lihatPesan()
{
    $this->load->model('notification_model');

    $data['num'] = $this->notification_model->cek_pesan();

    $this->load->view('notification/lihat_pesan',$data);

}

function tesNotif()
{
    $this->load->view('tes_notifikasi');
}

view notification(main view)
Code:
var x = 1;

        function cek(){

            $.ajax({
                url: "<?php echo base_url();?>main/cekPesan", //call the controller that load cek pesan view
                cache: false,
                success: function(msg){
                    $("#notifikasi").html(msg);
                }
            });
            var waktu = setTimeout("cek()",3000);
        }

        $(document).ready(function(){
            cek();
            $("#pesan").click(function(){
                $("#loading").show();
                if(x==1){
                    $("#pesan").css("background-color","#efefef");
                    x = 0;
                }else{
                    $("#pesan").css("background-color","#4B59a9");
                    x = 1;
                }
                $("#info").toggle();
                //ajax untuk menampilkan pesan yang belum terbaca
                $.ajax({
                    url: "<?php echo base_url();?>main/lihatPesan", //call the controller that load the lihat pesan view
                    cache: false,
                    success: function(msg){
                        $("#loading").hide();
                        $("#notifikasi").html(msg);
                    }
                });

            });
            $("#content").click(function(){
                $("#info").hide();
                $("#pesan").css("background-color","#4B59a9");
                x = 1;
            });
        });

view cek pesan
Code:
if($num > 0){
        echo $num;
    }

view lihat pesan
Code:
if($num>3){

        echo $num;

    }else{

        die ("<font color=red size=1>Tidak ada pesan baru yang belum dibaca</font>");

    }

When i run it,, the notification can't show,, althought i have update the database.. Thank you...