Jump to content

Recommended Posts

im trying to write a simple program to retrieve comments from a database using JQuery and ajax..

 

i am not sure how to correctly pass the data to the ajax to pull back the desired result.

 

this is the code i have so far.

 

js

 

$(document).ready(function(){


$.get("blog_files/getcomments.php",function(data){
    alert("Data Loaded: " + data);
  });


});

 

 

 

then the php it references

 

<?php

include("../dbconnect/dbconnect.php");

$blog_id = $_GET['blogid'];


$comments = mysql_query("SELECT * FROM blog_comments WHERE blog_id = $blog_id");
$nums = mysql_num_rows($comments);

if($nums == 1) { $string = " comment has been "; } 
	else {$string = " comments have been ";}


	echo "<h2 class='coms'>".$nums.$string." made about '".$title."'</h1>";

	while($rows = mysql_fetch_array($comments))
		{

		echo "<div id='comment'>";

		echo "<img src='".$rows['comment_pic']."'>";

		echo "<div class='cometwrap'>";
		echo "<h5>".$rows['name']."</h5>";
		echo "<p>".$rows['comments']."</p>";
		echo "</div>";

		if($_SESSION['login']['username'] == 'admin') {

		$comment_id = $rows['comment_id'];

		echo "<div id='delete'>delete</div>";
		echo "<input type='hidden' id='commentid' value='".$comment_id."'>";

		}

		echo "</div>";

		}

		echo "</a>";

?>

 

i need to pass the id of the blog that i am viewing to pull back teh right comments for that particular blog, but i dont know how to pass the id in the javascript.

 

 

SOMEONE HELP ME!!

Link to comment
https://forums.phpfreaks.com/topic/139311-need-help-with-jquery-and-ajax/
Share on other sites

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.