Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:41:19+00:00 2026-06-10T18:41:19+00:00

I’ve got my script working, but only 1 result shows up. What do I

  • 0

I’ve got my script working, but only 1 result shows up. What do I need to add to get next ten results from my database. I’ve provided small portions of the code which I feel are the most important for doing this.

AJAX

 <script type="text/javascript">
$(function() 
{
$('.load_more').live("click",function() 
{
var ID = $(this).attr("id");
if(ID)
{
$("#load"+ID).html('Loading...');

$.ajax({
type: "POST",
url: "include/load_more_home_posts.php",
cache: false, 
dataType: "json",
data: { streamitem_id: ID},
cache: false,
success: function(response){
$("#articles").prepend("<div id='divider-"+response['streamitem_id']+"'><div class='userinfo'><a href='/profile.php?username="+response['username']+"'><img class='stream_profileimage' style='border:none;padding:0px;display:inline;' border=\"0\" src=\"imgs/cropped"+response['id']+".jpg\" onerror='this.src=\"img/no_profile_img.jpeg\"' width=\"40\" height=\"40\" ></a><div class'delete' style='cursor:pointer;position:relative;top:0px;float:right;padding-right:5px;' onclick=\"delete_('"+response['streamitem_id']+"');\">X</div><a href='/profile.php?username="+response['username']+"'>"+response['first']+" "+ response['middle']+" "+response['last']+"</a><span class='subtleLink'> said</span><br/><a class='subtleLink' style='font-weight:normal;'>"+response['streamitem_timestamp']+"</a><hr>"+response['streamitem_content']+"<div style='height:20px;' class='post_contextoptions'><div id='streamcomment'><a style='cursor:pointer;' id='commenttoggle_"+response['streamitem_id']+"' onclick=\"toggle_comments('comment_holder_"+response['streamitem_id']+"');clearTimeout(streamloop);swapcommentlabel(this.id);\">Write a comment...</a></div><div id='streamlike'><a title='Like "+response['first']+" "+ response['middle']+" "+response['last']+"s status' id='likecontext_"+response['streamitem_id']+"' style='cursor:pointer;' onClick=\"likestatus("+response['streamitem_id']+",this.id);\"><div style='width:50px;' id='likesprint"+response['streamitem_id']+"'>Like</a></div><div style='width:50px;' id='likesprint"+response['streamitem_id']+"'><a title='See who likes "+response['first']+" "+ response['middle']+" "+response['last']+"s status' href='include/likes.php?streamitem_id="+response['streamitem_id']+"' /></a></div></div></form></div><div id='streamdislike'><a id='dislikecontext_"+response['streamitem_id']+"' style='cursor:pointer;' onClick=\"dislikestatus("+response['streamitem_id']+",this.id);\"><div style='width:70px;' id='dislikesprint"+response['streamitem_id']+"'>Dislike</a></div><div style='width:70px;' id='dislikesprint"+response['streamitem_id']+"'></div></div></form><div class='stream_comment_holder' style='display:none;' id='comment_holder_"+response['streamitem_id']+"'><div id='comment_list_"+response['streamitem_id']+"'></div><div class='stream_comment_inputarea'><form id='mycommentform' method='POST'  class='form_statusinput'>\
<input type='hidden'  name='streamidcontent' id='streamidcontent' value='"+response['streamitem_id']+"'>\
<input type='input' name='commentingcontents' id='commentingcontents' placeholder='Say something' autocomplete='off'>\
<input type='submit' id='button' value='Feed'><br/></div></div>").show();
// remove the previous load more link
$("#load"+ID).remove();
}
});
}
return false;
});
});
</script>

LOAD_MORE_HOME_POSTS

    <?php
session_start();
include("rawfeeds_load.php");

// get the article ID from ajax POST
if (isset($_POST['streamitem_id']) && $_POST['streamitem_id'] != "") {
$lastID = mysqli_real_escape_string($mysqli,$_POST['streamitem_id']);


 $following_string=mysqli_real_escape_string($mysqli,$_SESSION['id']);
 $sql_follows =  "SELECT * FROM friends WHERE user1_id=".$following_string." AND status=2 OR user2_id=".$following_string." AND status=2"; 
 $query_follows=mysqli_query($mysqli, $sql_follows) or die("Error finding friendships");


if($query_follows){
$friendlist="(".$_SESSION['id'].",";
$t=0;
while($follow=mysqli_fetch_array($query_follows))
{
if($follow['user1_id']==$_SESSION['id']){
if($t>0){
$friendlist=$friendlist.",";
}
$friendlist=$friendlist. $follow['user2_id'];
}else{
if($t>0){
$friendlist=$friendlist.",";
}
$friendlist=$friendlist. $follow['user1_id'];
}
$t=$t+1;
}
$friendlist=$friendlist.")";
}
//STREAMDATA
$badcall = "(".mysqli_real_escape_string($mysqli,$_SESSION['id']).",)";
if($friendlist==$badcall){
$friendlist="(".mysqli_real_escape_string($mysqli,$_SESSION['id']).")";
}
if(isset($_GET['limit'])){
$sqllimit = $_GET['limit'];
}else{
$sqllimit = 20;
}

$following_string = mysqli_real_escape_string($mysqli,$_SESSION['id']);
$call="SELECT * FROM streamdata WHERE streamitem_id < '$lastID' AND streamitem_target=".$following_string." OR streamitem_creator=".$following_string." OR streamitem_creator IN ".$friendlist." AND streamitem_target IN ".$friendlist." ORDER BY streamitem_id DESC LIMIT 10";
$chant= mysqli_query($mysqli, $call) or die(mysqli_error($mysqli));
$json = array();   
 while ($resultArr = mysqli_fetch_assoc($chant)) {
    $json[] = array(
        'streamitem_id' => $resultArr['streamitem_id'],
        'streamitem_content' => $resultArr['streamitem_content'],
        'streamitem_timestamp' => Agotime($resultArr['streamitem_timestamp'])
    );
}

$check = "SELECT comment_id, comment_datetime, comment_streamitem, comment_poster, comment_content FROM streamdata_comments WHERE comment_poster=".$following_string."  ORDER BY comment_datetime DESC";
$check1 = mysqli_query($mysqli,$check);
$resultArr = mysqli_fetch_assoc($check1);
$json['comment_id'] = $resultArr['comment_id'];
$json['comment_content'] = $resultArr['comment_content'];
$json['comment_poster'] = $resultArr['comment_poster'];
$json['comment_datetime'] = Agotime($resultArr['comment_datetime']);
$json['comment_streamitem'] = $resultArr['comment_streamitem'];



$check = "SELECT * FROM users WHERE id=".$following_string."";
$check1 = mysqli_query($mysqli,$check);
$resultArr = mysqli_fetch_assoc($check1);
$json['username'] = $resultArr['username'];
$json['id'] = $resultArr['id'];
$json['first'] = $resultArr['first'];
$json['middle'] = $resultArr['middle'];
$json['last'] = $resultArr['last'];


echo json_encode($json);

}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:41:20+00:00Added an answer on June 10, 2026 at 6:41 pm

    Right now you are not looping through your result set and therefore you are only fetching one row. Try the following, which splits your $json array into three arrays (streams, comments, users), which in turn are arrays (one for each row). Note that you will have to change your jQuery code accordingly.

    /***** STREAMS *****/
    $chant = mysqli_query($mysqli, $call) or die(mysqli_error($mysqli));
    $json = array();
    $json['streams'] = array();
    
    while ($resultArr = mysqli_fetch_assoc($chant)) {
        $arr = array();
        $arr['streamitem_id'] = $resultArr['streamitem_id'];
        $arr['streamitem_content'] = $resultArr['streamitem_content'];
        $arr['streamitem_timestamp'] = Agotime($resultArr['streamitem_timestamp']);
    
        $json['streams'][] = $arr;
    }
    
    /***** COMMENTS *****/
    $check = "SELECT comment_id, comment_datetime, comment_streamitem, comment_poster, comment_content FROM streamdata_comments WHERE comment_poster=".$following_string."  ORDER BY comment_datetime DESC";
    $check1 = mysqli_query($mysqli,$check);
    $json['comments'] = array();
    
    while ($resultArr = mysqli_fetch_assoc($check1)) {
        $arr = array();
        $arr['comment_id'] = $resultArr['comment_id'];
        $arr['comment_content'] = $resultArr['comment_content'];
        $arr['comment_poster'] = $resultArr['comment_poster'];
        $arr['comment_datetime'] = Agotime($resultArr['comment_datetime']);
        $arr['comment_streamitem'] = $resultArr['comment_streamitem'];
    
        $json['comments'][] = $arr;
    }
    
    /***** USERS *****/
    
    $check = "SELECT * FROM users WHERE id=".$following_string."";
    $check1 = mysqli_query($mysqli,$check);
    $json['users'] = array();
    
    while ($resultArr = mysqli_fetch_assoc($check1)) {
        $arr = array();
        $arr['username'] = $resultArr['username'];
        $arr['id'] = $resultArr['id'];
        $arr['first'] = $resultArr['first'];
        $arr['middle'] = $resultArr['middle'];
        $arr['last'] = $resultArr['last'];
    
        $json['users'][] = $arr;
    }
    
    
    echo json_encode($json);
    

    As for the jQuery, I will just show you an example of what you can do because I don’t know what your DOM looks like, and your code is not that simple. You should be able to update your code without any major headaches.

    success: function(response) {
        // Streams
        $.each(response.streams, function(i, stream) {
            alert(response.streams[i].streamitem_id);
        });
    
        // Comments
        $.each(response.comments, function(i, comment) {
            alert(response.comments[i].comment_id);
        });
    
        // Users
        $.each(response.users, function(i, user) {
            alert(response.users[i].id);
        });
    }
    

    Edit: In the above, it would be prettier to use the stream, comment and user variables directly instead of looking up at the arrays at position i.

    Also, I would suggest that you split your script into several scripts which have a more narrow focus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.