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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.