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.
精彩评论