Welcome Guest, Not a member yet? Register   Sign In
Codeigniter NotificationDrodownData dropdown menu
#1

        Hello 
am trying to get notifications for user everything works but i get wired data with \t\t\t\t\t\t\t\t\t\t\t Vp and Vdiv etc
here is my code:
Model

PHP Code:
    public function getNotifcations($data_passed){
                
$userLoggedIn $this->session->userdata('user_id');
                
                
$data = array(
                    
'viewed' => 1,
                );
                
$this->db->where('user_to'$userLoggedIn);
                
$this->db->update('notification'$data);
                
//invisibility spell
                
$this->db->where('user_to'$userLoggedIn);
                
$this->db->order_by('notification_datetime''DESC');
                
$query $this->db->get('notification');

                if (
$data_passed) {
                    return 
$query->result_array();
                }else{
                    return 
$query->num_rows();
                }
      }

      public function getCommentedUserData($uid){
            
$this->db->where('user_id'$uid);
            
$query $this->db->get('users');
            return 
$query->result_array();
      
Controller:

PHP Code:
        public function getAllNofications(){
            
$page $this->input->post('page');
            
$limit 7;
            
$userLoggedIn $this->session->userdata('user_id');
            
$return_string "";

            if(
$page == 1)
                
$start 0;
            else 
                
$start = ($page 1) * $limit;

            if(
$this->Post_model->getNotifcations(false) == 0) {
                echo 
"You have no notifications!";
                return;
            }

            
$num_iterations 0;
            
$count 1;

            foreach(
$this->Post_model->getNotifcations(true) as $row) {
                
//die(print_r($row['user_from']));
                
if($num_iterations++ < $start)
                    continue;

                if(
$count $limit)
                    break;
                else 
                    
$count++;

                
$user_from $row['user_from'];
                
$user_data $this->Post_model->getCommentedUserData($user_from);

                
$opened $row['opened'];
                
$style = ($opened == 0) ? "background-color: #DDEDFF;" "";

                
$return_string .= "<a href='".$row['link']."'> 
                                        <div class='resultDisplay resultDisplayNotification' style='"
.$style."'>
                                            <div class='notificationsProfilePic'>
                                                <img src=' assets/images/profileimages/"
.$user_data[0]['image']."'>
                                            </div>
                                            <p class='timestamp_smaller' id='grey'>"
.get_time_ago($row['notification_datetime'])."</p>".$row['message']."
                                        </div>
                                    </a>"
;
            }


            
//If posts were loaded
            
if($count $limit)
                
$return_string .= "<input type='hidden' class='nextPageDropdownData' value='" . ($page 1) . "'><input type='hidden' class='noMoreDropdownData' value='false'>";
            else 
                
$return_string .= "<input type='hidden' class='noMoreDropdownData' value='true'> <p style='text-align: center;'>No more notifications to load!</p>";
            
            



            echo 
json_encode($return_string);
        } 
So when i click my fa-user in navbar and scroll this happens :

Code:
<script>

function getDropdownData() {

    if($(".dropdown_data_window").css("height") == "0px") {

      $.ajax({
        url: "<?php echo base_url('posts/getAllNofications') ?>",
        type: "POST",
        data: {"page":1},
        cache: false,
        success: function(response) {
          $(".dropdown_data_window").html(response);
          $(".dropdown_data_window").css({"padding" : "0px", "height": "280px", "border" : "1px solid #DADADA"});
          //$("#dropdown_data_type").val(type);
          $("span").remove("#unread_notification");
        },
        error: function(){
          alert("Sorry something went wrong");
        }

      });

    }
    else {
      $(".dropdown_data_window").html("");
      $(".dropdown_data_window").css({"padding" : "0px", "height": "0px", "border" : "none"});
    }

  }


  var userLoggedIn = '<?php echo $this->session->userdata('user_id'); ?>';

  $(document).ready(function() {

    $('.dropdown_data_window').scroll(function() {
      var inner_height = $('.dropdown_data_window').innerHeight(); //Div containing data
      var scroll_top = $('.dropdown_data_window').scrollTop();
      var page = $('.dropdown_data_window').find('.nextPageDropdownData').val();
      var noMoreData = $('.dropdown_data_window').find('.noMoreDropdownData').val();

      if ((scroll_top + inner_height >= $('.dropdown_data_window')[0].scrollHeight) && noMoreData == 'false') {

        var type = $('#dropdown_data_type').val();
        var ajaxReq = $.ajax({
          url: "<?php echo base_url('posts/getAllNofications') ?>",
          type: "POST",
          data: "page=" + page + "&userLoggedIn=" + userLoggedIn,
          cache:false,

          success: function(response) {
            $('.dropdown_data_window').find('.nextPageDropdownData').remove(); //Removes current .nextpage
            $('.dropdown_data_window').find('.noMoreDropdownData').remove(); //Removes current .nextpage


            $('.dropdown_data_window').append(response);
          }
        });

      } //End if

      return false;

    }); //End (window).scroll(function())


  });

  </script>
The data that is shown is like this :
pic1=  https://www.dropbox.com/s/m5ee9yb5up37ht...9.png?dl=0
pic2= https://www.dropbox.com/s/lsohgvn7dfmxir...9.png?dl=0
pic3= https://www.dropbox.com/s/9b0ul0e79m7xvf...9.png?dl=0

am trying something youtube notification dropdown
Reply
#2

I'm just going to guess here really, as it's hard to check the outputted data. But replace echo json_encode($return_string); with just echo $return_string;
Reply
#3

(09-25-2019, 10:35 AM)jreklund Wrote: I'm just going to guess here really, as it's hard to check the outputted data. But replace echo json_encode($return_string); with just echo $return_string;
yes it works thank you. 
and it turns out that i should specify the data type if i do json_encode() datatype:' json',
Reply




Theme © iAndrew 2016 - Forum software by © MyBB