The following query will create a random vote of between 50 and 100 for each rateable value.
- INSERT INTO rabid_ratings (ratable_id, ip_address, rating, TIMESTAMP)
- SELECT rabid_ratables.id AS ratable_id,CONCAT(FLOOR(1 + (RAND() * 255)),'.',FLOOR(1 + (RAND() * 255)),'.',FLOOR(1 + (RAND() * 255)),'.',FLOOR(1 + (RAND() * 255))) AS ip_address,FLOOR(50 + (RAND() * 51)) AS rating,NOW() AS TIMESTAMP
- FROM rabid_ratables
- ORDER BY RAND();
Test this data with the following:
SELECT ratable_id,COUNT(ratable_id),ROUND(SUM(rating)/COUNT(ratable_id)) AS vote FROM rabid_ratings GROUP BY ratable_id ORDER BY vote DESC;
The only problem with this is that all of the ratings have the same amount of votes, which makes it look very contrived. Even though it is, we don't want to make it look like that. The solution to this is to delete a random number of votes for each ratable value. The only problem is that you can't use the RAND() function within the LIMIT clause of a MySQL statement. So therefore you can use the following bit of PHP to delete a random number of votes.
echo 'DELETE FROM rabid_ratings WHERE ratable_id = 1 ORDER BY RAND() LIMIT '.rand(1,100).';';
By incorporating this into a mysql_connect() function call you can run it for every rateable value and make it look like some items have more votes than others.