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