开发者

php script for star rating in admin panel?

开发者 https://www.devze.com 2023-03-20 19:27 出处:网络
I am new to php. I have a site which have admin section.here i want开发者_StackOverflow中文版 admin to rate the products he is having and that rating should be stored in database.

I am new to php. I have a site which have admin section.here i want开发者_StackOverflow中文版 admin to rate the products he is having and that rating should be stored in database.

I don't have any idea about this. Please anybody help me with some examples.


On a high level this is what you need to do.

In your database, add a new column:

ALTER TABLE `products` ADD COLUMN `star_rating` INT(1) NOT NULL DEFAULT 0;

Store a value that the user has clicked on, which will be either 0 to 5.

On output, you can output X stars with something such as the following:

<strong>Rating:</strong> <?php echo str_repeat('<img src="/star.png" alt="*" />', $row['star_rating']) ?>

.. where $row is a mysql_fetch_assoc() result from SELECT * FROM products.

This is however all extremely basic and will be covered off in even the simplest of PHP/MySQL tutorials, you should really learn the language.


You can achieve this by many ways.. one way is you allow user to rate product and you can store ratings in one db column which entered by admin and then you can always print it.

0

精彩评论

暂无评论...
验证码 换一张
取 消