I have 2 pages in PHP ( insert.php , retrieve.php )
insert.php , has the following:
1)Form 2)inputbox 3)submit button(insert) 4)div (div id='data').
retrieve.php :
has code to retrive/select rows from MySQL database(table) : MySQL."Select * from table"........ while(...) { .. }
I need ajax code/jQuery , whatever to keep retrieving(getting) results from retrive.php and put them into div id='data' without page refresh . maybe this has to set a timer=1sec .
Use setTimeout(function, millisDelay)
setTimeout(function()
{
$("form").submit(function() {
jQuery.post({
type: 'POST',
url: "retreive.php",
data: FORM_PARAMETERS_HERE
});
return true;
});
}, 1000); //1000 milisec = 1 sec
What you need:
For example,
Your php script might look similar to this one:
<?php
//suppose we already connected
$query = "SELECT * FROM `some_table` WHERE ...";
$result = mysql_query($query);
//Just Ensure that it's not FALSE
if ( !$result ){
die('wrong query');
}
while ($row = mysql_fetch_assoc($result)){
print $row['column']; /// and so on..
}
Ok, suppose you already know that it does work.
Now you'd implement timer to retrieve that after 1 sec (==1000m) And you have to change the content of the div accordingly.
<script>
$(function(){
setTimeout(function(){
$.post('path_to_your_scr_php.php', { /* Data in JSON format, if needed, use it like: key: val */ }, function(respond){
$("#id_of_the_div_you_want_to_change").html(respond);
})
}, 1000);
});
</script>