tags:

views:

120

answers:

5

i have a page on which i have some rating function like people who like the post can rate up or who don't can rate down.

on that link im calling a php file with some parameters passed in the anchor tag. Then in that php file im saving that rating with +1 or -1 (whichever is the case) in the database and after doing that im redirecting to that first page from where we have rated. Now this whole function is reloading my whole page which i dont want.Is there any way with which i can do this rating without reloading the page,i want that when a person clicks on rate then just after click the rating should be shown according to what the user just did(+ or -) and that too without reloading the whole page.Is there any way to do that in php???????

+4  A: 

Yes, it's called "Ajax". However, you don't do this on the server-side with PHP, you do it on the client-side with JavaScript. There are plenty of tutorials around, I suggest you take a look.

Note that there are many JavaScript libraries out there to make this extremely easy. I'd recommend taking a look at jQuery because I've personally found it to be the easiest to learn and use.

musicfreak
I would recommend using a javascript framework such as mootools, YUI or jQuery than using the bare bones XMLHTTP and JS.
Shoan
Point taken, edited.
musicfreak
A: 

Here i found a good tutorial for u :) http://sandbox.ronggur.com/2009/05/30/jquery-tutorial-simple-ajax-star-rating-with-php/ For this u must use jQuery libary

subprime
A: 

It seems a few answers have already been posted recommending different libraries. If you would like the avoid the (admittedly minimal) overhead of an included library, the following tutorial shows how to use a simple XMLHttpRequest object.

http://www.xul.fr/en-xml-ajax.html

The "xhr.responseText" is what you would receive back from the php processing (which would typically be done in a small, single-purpose script seperate from the primary page).

Jon
A: 

You can do this using Javascript or AJAX. There are plenty of free scripts online that can help you to do this without building the whole thing from scratch.

This page (http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=364) has a good list of different star rating scripts you can choose from. You can Google for more.

Stellaire
A: 

Here's another relevant tutorial I came across when answering some other question:

http://docs.jquery.com/Tutorials:Getting%5FStarted%5Fwith%5FjQuery#Rate%5Fme:%5FUsing%5FAjax

Jonathan Maddison