Jummy, welcome to the site…
Well, there are hundreds of ways to handle this. All quite easy. The hardest part will be tracking it all.
I will give you some ideas to start with and then as you progress, you can ask further questions of us.
First, in picking out randomly ordered ID’s from a table in a database, you can do that with ease in just
one simple query. Something similar to " $query="SELECT * FROM users ORDER BY RAND() LIMIT 200; "
As you see this pulls out all info from a table named ‘users’, randomly ordered and limits it to just 200
users. You would have to go a step further by knowing which panelists and who are not.
So, let’s say you have a table of users and you have a field in the table that is called “user_type”. For,
standard users, this would indicate, maybe “standard” and for a panelist, it would indicate “panelist”.
In this case, you would have your 200 panelists marked as so in the database user table. Then, you
would change the query to be more like this:
$query=“SELECT * FROM users WHERE user_type=‘panelist’ ORDER BY RAND() LIMIT 200”;
This type of query would pull 200 rand user’s out of all that have been marked as a user type of “panelist”.
So, that should be very easy enough to handle. Just need to know which users are panelists or not.
Then, comes the selection of the which panelist gets which blog to rate. So, you have a list of categories.
Same query works with some some changes. Just use something similar to this query:
$query=“SELECT * FROM categories ORDER BY RAND() LIMIT 10”;
What is will do is grab 10 categories randomly from your table. (Assuming it is named “categories”!)
You can then parse thru the list of of the 10 categories in the list to the panelists from the previous query.
The logic is fairly simple. You already know the user list. Which indicate the panelist’s. You have the full
category list. So, easy… The logic is something like this:
Run a query to locate a randomly selected 200 users who are marked as possible-panelist’s.
Loop thru that list using a WHILE loop
Inside this loop run a second query to locate a randomly selected 10 caterories
Save or send this list for the current user which is 1 of 200
loop thru all of the panelist’s in the loop
Done…
Now, one further thing to add in. You would need a bit of tracking on the selection process. The easiest
way would be to create a new table. Let’s call it “votes” for my example. In this voting table, you would
need to track a few items. First, the current voting cycle. So, you need a way to allow the panelist to
mark their votes. You must also have a way to dump the records or date them somehow. You wouldn’t
want to set up a vote today and have it still in effect five years from now. Also, you need to allow the
panelist to vote and then take the vote off their list. This is what I suggest you will need in your “votes”
table. This is just a list I would use and would make it easy for you to deal with everything…
vote_id (autoincrement, primary-key) Just used for displays and voting…
vote_panelist (integer) The ID of the user from the users table. Used to display the blog to the panelist
vote_status (text) This is the status of the vote, like “open”, “voted” or “expired”. Will explain later…
vote_results (integer) What the panelist selected as the vote, like 1 to 5 for top five or whatever…
Now, in your code when you run the new voting process, you would need to use the first query to get your
list of randomly selected panelist’s. Then, create an entry into the “votes” table for them using the second
query. You would create 100 entries for each panelist. 10 categories randomly selected times 10 blogs that
they need to vote for. And, of course set the status to “open” which means they need to vote on them and
the results set to zero. (A value above zero means they voted and selecte 1 to 5) This sound like a lot of
data and it is, about 100 times 200, but, nowadays, this is not really much database-wise.
Once this is completed, you should have a database table, I called “votes” with an entry for each of the
possible votes needed. Next, when a user logs into the site, you need to check if they are a panelist or not.
If they are, then you need to display the voting process. To do that it is very easy. Just run a query that
selects any pending votes they need to deal with. This would be handled something like this:
$query=“SELECT * FROM votes WHERE vote_panelist=” . $user_id . " AND vote_status=‘open’ ";
Note that this expects you to have the currently logged in user’s ID value in variable $user_id. You did
not explain your database layout, so this is just an example on how to run this query. This will grab all
of the votes that this user has not replied to. You would display an option where this list is displayed and
they can press a small button 1 to 5 to select that value. As they press the button, it would alter the DB
table. You would need to update the votes table with a query something like this at this point:
$query="UPDATE votes SET vote_status=‘voted’ ";
Basically, just changing the status of this one vote would make it so that it is not shown again for that user.
To handle the buttons, the simplest way would be just to use a form and have it repost to the same page
after it has updated the database. In this way, as the user selects the 1 to 5 for each of the blogs, they
would disappear as the page would reload and would not show the ones they already selected.
Lastly, the other issue to design would be to once this process is complete how you are going to display
the results and when is the progress over. If a user does not vote after a set time, do you remove them
or leave it going forever? Things like that would need to be sorted out.
Yikes! Lots of items for you to think about. First, create a list of data you need. Next, design the database
tables and think it all out. Then, start the programming by handling the inputs and the the displays…
Good luck! Hope all of this gives you a lot to start with! Any problems ask us!