-1

hello I have a php code that get contents from DB I want to load this contents in a div with "link" class without refreshing page

here is my code

<?
include('config.php');
$rs = mysql_query("SELECT *
FROM `database` order by desc limit 1");
while($rw = mysql_fetch_assoc($rs))
 $id = $rw['id'];
 
 
$title = $rw['title'];

?>

<div class="link">
<?
echo $title;
?>

</div>
Akh
  • 1
  • one word: [Ajax](https://developer.mozilla.org/en/docs/AJAX) – MIdhun Krishna Aug 03 '15 at 17:26
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Aug 03 '15 at 17:30

1 Answers1

0

Script for your web page:

{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("txtData").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "getData.php?q=" + str, true);
    xmlhttp.send();
}

then you need to create a getData php file that does your data execution in your question and barfs it up for the ajax call to dump in the txtData control (or wherever else you want the data to go.)

Clay Sills
  • 235
  • 1
  • 9