Jump to content

Displaying database records, before and after inserting new record


beanymanuk

Recommended Posts

I'm trying to display records from a database and then when a new one is added automatically update the displayed records from the database with the new one

 

I am doing this using php and javascript. I want to load a page and display tags under a video and then when a user adds a new tag by entering it into text box to add it to the database and then refresh the part of the page which shows these tags and include the new tag which has just been added all without the page being reloaded.

 

I am using code from this link as my base to add records http://www.9lessons.info/2009/05/insert-and-load-record-using-jquery-and.html

Link to comment
Share on other sites

If you are thinking that you want Javascript to create a new row in the table and also send the new data to the database then you are looking at AJAX (which you knew - sorry!). 

 

You would get Javascript to request a PHP page sending the data to it as POST or GET.  The page would then do the database handling.  Otherwise you would need to reload the main page.

 

Have a look at any basic AJAX tutorial if you need to (it's basic stuff - just two things to learn if you already know Javascript and PHP - XMLHttpRequest() and the request object).

Link to comment
Share on other sites

I started a thread that discussed exactly this scenario.  Check it out here:

 

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

 

 

Basically is uses ajax to populate the contents of a div tag on the page.  There are basically 3 actions:

 

1. add

2. delete

3. everything else (which just means to draw the table without adding or deleting anything from it)

 

 

If you add a user, then it updates the MySQL table and then refreshes the table in the page (without refreshing the entire page).  It's almost instant...you fill in the data, click add, and the HTML table gets updated.  If you deleted, the same thing happens.

 

 

All of the code is there for you in that post.  Pay particular attention to my final post though...make sure to edit the javascript code and use & instead of ?...it will make parsing the input orders of magnitude easier.  ;)

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.