Hi I am making a shopping site and wish to display some user ranks.
How can i rank each user for a certain field, and then insert the user's rank
into a corresponding field for each user? Ranking is detarmined based on the
number of transaction made. Actual rank is Premium(more than
100teransaction)/Gold(60-99)/Silver(30-59)/Bronze(0-29) )
Depend on the rank, different comission fee is applied.
Thanks for your help.
Help me with PHP coding
Moderator: General Moderators
Re: Help me with PHP coding
Are you able to get that "number of transactions made" figure yet?
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: Help me with PHP coding
Hi,
Just to add to what requinix is saying, I think you will need to run a database query to count the number of transactions that user has made each time they make a new transaction and then update their record in the database. In theory, it would be easier to just calculate the number of transactions that each user has made every time their rank needs to be displayed or calculated and then use a look-up table in your script to determine what their rank is, but you will be running this query every time this information is needed so it would be better to update their record with the number of transactions they have made. From a maintenance perspective, it is probably best to just record the number of transactions rather than the rank itself, because you might decide to revise the ranking scheme at some point.
To count their number of transactions you could do something like this:
Note that only one result will be retrieved with this query and you will need to assign the "total" value to a variable.
You could then have a lookup table in your script that does something like this:
There are lots of different ways to do this and this is obviously just one example.
HTH,
Mecha Godzilla
Just to add to what requinix is saying, I think you will need to run a database query to count the number of transactions that user has made each time they make a new transaction and then update their record in the database. In theory, it would be easier to just calculate the number of transactions that each user has made every time their rank needs to be displayed or calculated and then use a look-up table in your script to determine what their rank is, but you will be running this query every time this information is needed so it would be better to update their record with the number of transactions they have made. From a maintenance perspective, it is probably best to just record the number of transactions rather than the rank itself, because you might decide to revise the ranking scheme at some point.
To count their number of transactions you could do something like this:
Code: Select all
SELECT COUNT(transactionID) AS total
FROM transactions
WHERE userID = '1234'You could then have a lookup table in your script that does something like this:
Code: Select all
$ranking = 8; // placeholder for the value retrieved from the last query
switch (1) {
case $ranking >= 0 && $ranking <= 29:
echo 'Bronze';
break;
case $ranking >= 30 && $ranking <= 59:
echo 'Silver';
break;
case $ranking >= 60 && $ranking <= 99:
echo 'Gold';
break;
case $ranking >= 100:
echo 'Platinum';
break;
default:break;
}HTH,
Mecha Godzilla
Re: Help me with PHP coding
Thanks a lot you guys! That is a Great Help. I will try with this.
Re: Help me with PHP coding
Hello...I think you will need to work with some database queries for transaction.