JQuery + Ajax + PHP "like" rating function implementation code

Source: Internet
Author: User
Based on jQuery, this article uses PHP and mysql to provide a rating function. It is a simple and very good ajax application instance. For more information, see

Based on jQuery, this article uses PHP and mysql to provide a rating function. It is a simple and very good ajax application instance. For more information, see

This article introduces a jQuery + Ajax + PHP code for implementing the "like" rating function. When you click the red-hearted button on your favorite image on the page, the front-end page sends an ajax request to the backend. After receiving the request, the PHP program in the backend queries whether the user's click record exists in the IP address library. If not, the corresponding value is + 1, at the same time, the user's IP information is written to the IP database, and vice versa, the user is "liked ".

Database Design
Prepare two tables. The pic table stores the image information, including the image name, path, and total number of "liked" images. pic_ip records the IP address data after the user clicks the favorite image.

Create table if not exists 'pic '('id' int (11) not null AUTO_INCREMENT, 'pic _ name' varchar (60) not null, 'pic _ url' varchar (60) not null, 'love' int (11) not null default '0', primary key ('id ')) ENGINE = MyISAM default charset = utf8;

Create table if not exists 'pic _ ip' ('id' int (11) not null AUTO_INCREMENT, 'pic _ id' int (11) not null, 'IP' varchar (40) not null, primary key ('id') ENGINE = MyISAM default charset = utf8

Index. php
In index. php, we use PHP to read and display the image information in the pic table, and use CSS to improve the page display effect.
The Code is as follows:

JQuery + Ajax + PHP achieves "like" rating

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.