1

I want that if i click on an anchor tag it shows the mysql database table values

for example

 <a href"#">Click to show comments</a>

 after clicking

 it will do something like this

    SELECT * FROM `comments`LIMIT 0 , 30

1 Answer 1

2

I think you would need to use AJAX, I advice you to use jQuery for this purpose.

using jquery you would have to do something like

in your HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<a id="foobar "href="#">Click to show comments</a>
<div id="comments"></div>
<script>
$(document).ready(function(){
   $('#id').click(function(){
      $.ajax({
          url: "comment.php",
          dataType: 'json',
          success: function(data){
            foreach(v in data) {
              $('#comments').append(data[v]);
            }
          }
      });
   });
});

You would have to put together the comment.php script that would output the data retrieved from the database and use json_encode to encode it in JSON

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.