Jump to content

Recommended Posts

So I have a script I'm working on that pulls multiple comments from a database, then puts it in a jquery piece that pulls the data from the arrays I created in my MYSQL Select.

Below is the results I get, and I want to combine the 2 queries because the information that I get is correct, however they are basically seperate arrays, hence the Undefined.

I have something like that to get the arrays,

$json = array_merge($names, $posts);
return json_encode($json);

and this is the result by using array_merge

undefinedName1
undefinedName1
undefinedName1
undefinedName2
undefinedName2
Post1undefined
Post1undefined
Post1undefined
Post2undefined
Post3undefined

 

Below if the javascript piece that I am using for this, can I split out the .html()? Because I have also done a bunch of unions and LEFT JOINS to my sql and can get most of the information I want into one array, but when I do this and try to echo the Posts, then it will echo the post 3 times instead of once if I have 3 comments, so I can't strip out the comments this way. Or is there a better way of doing this? Below is my javascript.

$(document).ready(function(){
		//settings on top
		var domain = 'http://test.com/';
		var initialPosts = <?php echo get_posts(0,$_SESSION['posts_start']); ?>;
		//function that creates posts
		var postHandler = function(postsJSON) {
			$.each(postsJSON,function(i,post) {
				//post url
				var postURL = '' + domain + post.PostID;
				var id = 'post-' + post.PostID;

				//create the HTML
				$('<div></div>')
				.addClass('post')
				.attr('id',id)
				//generate the HTML
				.html('<tr><td>' + post.Name+ '' + post.Post+'</td></tr>')

				.click(function() {
					window.location = postURL;
				})
				//inject into the container
				.appendTo($('#posts'))
				.hide()
				.slideDown(250,function() {
					if(i == 0) {
						$.scrollTo($('div#' + id));
					}
				});
			});	
		};

 

My biggest problem is only getting one post, but getting all the comments that were posted to this array doing it this way.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.