Jump to content

displaying contents from database without reloading a page using PHP


Recommended Posts

Hi, I am currently learning MySQL and PHP and I wonder if it is possible to display contents from database without reloading a page using PHP script only. Please consider the following situatioin.

 

There is a table named 'ta' in the database named "db". And the table has the following contents.

 

ta

-----------------

site  | score

-----------------

google | 99

-----------------

yahoo  | 98

 

From this I can dispaly the score fairly easily using the following script:

 

 

$db_conn = new mysqli('localhost', 'username', 'password', 'db');

 

$query = 'select * from ta ' ."where name='$site'";

 

But it has to reload the page. If you know how to do this without page reloading please provide me some code.

 

Thanks.

Well, not really... PHP stands for Post Hypertext Processor, meaning that it already figures out all the results of your code before being fully loaded, so you're right in saying that it can not do it without reloading the page. It basically is just HTML by the time it gets to your browser.

 

But, there's good news! With AJAX, we can do this by using Javascript to load the contents of a page and add it to the currently existing DOM. For super duper ease,  I recommend using jquery.

 

http://api.jquery.com/load/

Someone else just asked this very same question a few days ago:

 

http://www.phpfreaks.com/forums/index.php/topic,292404.0.html

 

 

You can look at that post and see my response or you can go directly to the thread that I started about this:

 

http://www.phpfreaks.com/forums/index.php/topic,287155.0.html

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.