How to realize the rating function of jQuery+Ajax+PHP
This article mainly introduces the relevant knowledge of "how to achieve the rating function of jQuery+Ajax+PHP". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to achieve the rating function of jQuery+Ajax+PHP" can help you solve the problem.
Realization process
When the user clicks the Hearts button on his favorite picture on the page, the front page sends an ajax request to the background. After receiving the request, the background PHP program queries whether there is a click record of the user in the IP library. If not, the corresponding value is + 1. At the same time, the user's IP information is written to the IP library, otherwise, the user is told that he has "liked it".
Database design
First, prepare two tables. The pic table stores the picture information, including the corresponding name, path and the total number of "likes" of the picture. Pic_ip records the IP data after the user clicks on it.
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 '0mm, 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 read the picture information in the pic table through PHP and display it, combined with CSS to improve the display effect of the page.