i have an ajax script and a php file on the server that inserts new post to the database, the ajax script can post to the target php file and get a response as json data (which is decoded and echo as HTML data which is my posts) which I use to append to a div. however, my solution returns the entire result from my database, i.e all my posts that my query returns via mysql_query. how do i get only results that are recent or at least how do i get only my last post;
$(function() {
$("#PostItemz").on('submit', function(event){
event.preventDefault()
var formData = new FormData(this);
$.ajax({
url: 'inc/modules/post_data.php',
type: 'POST',
data: formData,
success: function (data) {
//here the data return is my post as html object
//data is return via echo on another php page
console.log(data);
$('#postarea').append(data);
$("#PostItemz")[0].reset();
$('.inner-addon, .left-addon, .create-text').hide();
},
cache: false,
contentType: false,
processData: false
});
});
});
AND this is my php code: on server that returns the post data:
<?php
function getFollowedGroupPosts($user_id){
$sql_query = mysql_query("SELECT gid FROM members WHERE uid = '$user_id'");
//iterate through record set, push records into user defined record_set[] array and return array as json encoded data
.
.
.
.
.
$record_set[] = array('gid' => $rows_b['gid'],
'pid' => $rows_b['pid'],
'post' => $rows_b['post'],
'images' => getPostImages($rows_b['pid']),
'jImages' => $url_string,
'videos' => getPostVideos($rows_b['pid']),
'audios' => getPostAudios($rows_b['pid']),
'date' => timeAgo($rows_b['date']),
'username' => userIdToName($rows_b['uid']),
'filemap_id' => $rows_b['filemap_id'],
'group_name' => groupIdToName($rows_b['gid']),
'comments' => getComments($rows_b['pid']),
'likes' => checkLikeCount($rows_b['pid']),
'dislikes' => checkDislikeCount($rows_b['pid']),
'post_count' => $row_count_b);
}
}
return $record_set;
how do i make async ajax calls to php and what query do i use on server side to return recent posts other than the ones on my page already