Forum Moderators: open

Message Too Old, No Replies

How to retrieve records from mysql with ajax + php

ajax, myslq,php

         

rodriguez1804

12:00 pm on May 5, 2010 (gmt 0)

10+ Year Member



Hey guys,

I am using ajax and php to insert comments from users into the database. I have it to where after the user submits a comment, that most recent comment shows up on the page, but after refresh, all the displayed records are gone. The comments still remain in db, but not the page itself. It's because of the refresh, but I want them to remain on the page.

That said, I already have a function that retrieves the comments from the db written in php. Is there any way to just send the most recent comment to this php function so that the most recent comment shows up WITHOUT having to refresh the page? or do I have to create a function using ajax to retrieve the records? If I have to do it in ajax, can somebody please show me an example of how to fetch a record from a database and display it to a specified page? Thanks for the help.

rodriguez1804

2:45 pm on May 5, 2010 (gmt 0)

10+ Year Member



never mind, I got it working. All I had to do was:

1.) Modify my php function to "echo" the resulting comments I wanted to print instead of
"return" them.
2.) Call this function from a div I had already created to display the new comments.

Not sure if this is the correct way to go about it, but it works, and that's all I needed. Thanks again.