jQuery, Ajax, SQL Pagination, problems with SESSION

350
November 22, 2016, at 1:12 PM

This is my first time doing pagination with jQuery ajax. I do it like this:

I include file 'GetAllMessages.php' into a div, only if i'm logged in.[works]

I include file 'GetMessages.php' again only if im logged in which tells me how many messages are in database.[works]

When I click on my 'messages' link I open a popup and I get my first four messages from 'GetAllMessages.php'.[works]

At the end of this div i have pages like [1,2,3...] and then with jquery $.ajax function (post method) i go again into 'GetAllMessages.php' but this time I tell the file which page I clicked so it gives me the messages I want next.[doesnt work]

It's like SESSION does not exsist, but if I add 'SESSION_START' at start in 'GetAllMesasages.php' it says its already started on my initial 'GetAllMessages.php' load, but when I click on page link[1,2,3...] the error goes away and it all works.

GetAllMessages.php

<?php
if(isset($_SESSION["uname"])){
include ('config.php');
include ('getMessages.php');
$pages=$messageCount/$messagesPerPage;
if(isset($_POST["page"])){
$page=$_POST["page"];
}else{
$page=1;
}
$startQuery=($page-1)*$messagesPerPage;
$getMessagesQuery = "SELECT * from messages ORDER BY id DESC LIMIT ".$startQuery.",".$messagesPerPage."";
$result = $conn->query($getMessagesQuery);
if($result->num_rows>0){
    while($row=$result->fetch_assoc()){
        $mId=$row["id"];
        $mName=$row["name"];
        $mEmail=$row["email"];
        $mMessage=$row["message"];
        $mDate=$row["messageDate"];
        $mIsRead=$row["seen"];
        $mIsAnswered=$row["answered"];
        if($mIsRead==0){
            $messageStatus="unread";
            $markReadButton="<button class='button1'>Mark as read</button>";
        }else if($mIsAnswered==1){
            $markReadButton="";
            $messageStatus="answered";
        }else{
            $markReadButton="";
            $messageStatus="";
        }                       
        echo "
        <div class='message ".$messageStatus."' data-messageid='".$mId."'>
            <p class='date'>".$mDate."</p>
            <p class='sender'>".$mName." - ".$mEmail."</p>
            <p class='messageContent'>".$mMessage."</p>
            <span class='buttons'>              
            <button class='reply'>Reply</button>
            ".$markReadButton."
            </span>
        </div>";
    }
}
}else die();
?>
READ ALSO
Phonegap Android Build Does Not Connect to Other Servers

Phonegap Android Build Does Not Connect to Other Servers

When I make an android build with phonegap, download it on my phone and launch it, it wont make the webservice calls. In fact it wont retrieve the JQuery files from the cdn link that I have in the header.

273
Can I have the cursor start on a particular column by default in jqgrid&#39;s edit mode?

Can I have the cursor start on a particular column by default in jqgrid's edit mode?

When editing a row on jqgrid, the cursor automatically enters the left-most editable field. Is there a way to have it default to a particular column, or better yet, to whatever column I click on?.

403
Show partial using ui.bootstrap collapse

Show partial using ui.bootstrap collapse

I have a row of buttons in my Angular. js application that currently open up a new route, showing a new partial view on the page.

461