-3

Simply, I have an <a> tag having values(ID) which will be posted to the same page in clicking,

I wanted to load data into the table based on the ID provided by the post method. On the other hand I am having a clock which is rested again and again when fired a post method.

I simply wanted to do the same via jQuery.

In short I wanted to Implement ajax using jQuery

Also I am using database MySQL, with PHP scripting

Any sort help will be appreciated.

<a class="D" href="?ID=<?php echo $rows[0]; ?>" onclick="">Question<?php echo $QNo; ?></a>

I wanted the same above and get ID for searching relevant data against the ID.

Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82
  • 1
    Have you tried anything? – putvande May 08 '14 at 14:30
  • Here is a good example/explanation of jQuery Ajax with PHP: http://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php – felipekm May 08 '14 at 14:32
  • What are you trying to do. Why is the clock worth mentioning? Why do we need to know about your MySQL db? Have you tried anything at all? – the_pete May 08 '14 at 14:33

1 Answers1

0

I might be wrong here, but you basically want to query a PHP page based on an ID and display relevant content in a div?

To make an AJAX call, setup a PHP page that will query your database and in turn return HTML data which you can then display in a DOM element.

A very simple example of this would be:

HTML

<a href="#" data-tableId="1" class="linkToLoadTable">Load table 1</a>
<a href="#" data-tableId="2" class="linkToLoadTable">Load table 2</a>
<div id="contentToPopulate"></div>

jQuery:

$('a.linkToLoadTable').click(function(){
    var pageId = $(this).data('tableId')
    $.ajax({
        url: 'loadTable.php?id='+pageId
    }).done(function(data) {
        $('#contentToPopulate').html(data)
    });
})
marcjae
  • 1,372
  • 8
  • 8
  • first thing I do not wanted to use Ajax I wanted to do the work with jquery and also I wanted to sent some unique ID for "where clause" so that I can fetch via php and Dear Sir kindly tell me that what is "data-tableId" over here is that same data-tableId=tableId – Shivam Shukla May 09 '14 at 10:58
  • @ShivamShukla "$.ajax" is a jQuery method to perform a asynchronous HTTP request. With regards to "data-tableId". It is a data attribute we are using to pass a variable (in this case, an integer). So expanding on the example above. You would need to include something like "$tableRow = $_SERVER['QUERY_STRING'];" in loadTable.php. Then your SQL query would be along the lines of "mysql_query("SELECT name FROM users WHERE id='$tableRow '")" – marcjae May 12 '14 at 07:23