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

  • SEARCH
  • Home
  • 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 7844279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:49:28+00:00 2026-06-02T16:49:28+00:00

I use a comment box in my web page and saved user input comments.

  • 0

I use a comment box in my web page and saved user input comments. Now what I want is to display them using AJAX. I set a javascript timer to get comments one by one. But I don’t know how to use AJAX to retrieve data. This is the php file

<?php
$link = mysql_connect("localhost","root","");
mysql_select_db("continental_tourism");
$query = "SELECT comment_id from comment";
$result = mysql_query($query);
$counter = 0;
while ($row = mysql_fetch_assoc($result))
{
$counter++;
} 

$comment_number = rand(1,$counter);
$query_comment = mysql_query("SELECT * FROM comment WHERE comment_id = '$comment_number'");
if (!$query_comment) { 
die('Invalid query: ' . mysql_error());
}   
while($result_comment = mysql_fetch_array($query_comment)) {

echo $result_comment['comment'];

}
?>

following is the script part in the main file.

function timeMsg()
{
var t=setTimeout("show_comment()",3000);
}

function show_comment(){

}

How should i write the AJAX code to the?

function show_comment()

If someone can explain the AJAX code line by line, I’ll be great full.

  • 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-02T16:49:30+00:00Added an answer on June 2, 2026 at 4:49 pm

    You have to move your all php script to another php file say getdata.php and use your ajax function in your file where you want to show the data say it is index.php. (this is for easy to use code). Now your index.php file should look like

    <html>
      <body>
        <div id="comments"></div>
      </body>
      <script src="include/jquery.js" type="text/javascript"></script>
      <script type="text/javascript>
        function show_comments() {
             $.ajax({
                url:getdata.php
                success:function(data){
                   $("#comments").append(data);
                }
             }); 
      </script>
     </html>
    

    I am using jquery.ajax function of jquery. This is some hint how you can do this. I hope it will help you to accomplish your task.

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

Sidebar

Related Questions

I need to use AJAX to save user input comments instantly to the database.
I want to allow HTML in a comment box (eventually use tinymce or something
We use comment moderation, and the graph API is returning everything (including comments that
I want to use django.contrib.comments in a blogging application and customize the way the
I want to create conditional comments in XSLT. But when I use this: <!--
I tried to use a Facebook comment plugin so that I can moderate comments
I have webpage that has details view. I want to add comment box where
I have a web page that displays comments, and users can click a 'Flag'
I want to design some speech bubble like comment box in HTML with CSS.
I want to find the universal way to scroll to comment box in WP

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.