Page 1 of 1
Help me with PHP coding
Posted: Thu Aug 01, 2013 2:00 pm
by mimic
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.
Re: Help me with PHP coding
Posted: Thu Aug 01, 2013 2:47 pm
by requinix
Are you able to get that "number of transactions made" figure yet?
Re: Help me with PHP coding
Posted: Thu Aug 01, 2013 2:53 pm
by mecha_godzilla
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:
Code: Select all
SELECT COUNT(transactionID) AS total
FROM transactions
WHERE userID = '1234'
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:
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;
}
There are lots of different ways to do this and this is obviously just one example.
HTH,
Mecha Godzilla
Re: Help me with PHP coding
Posted: Fri Aug 02, 2013 12:58 pm
by mimic
Thanks a lot you guys! That is a Great Help. I will try with this.
Re: Help me with PHP coding
Posted: Mon Aug 05, 2013 8:34 am
by haley01
Hello...I think you will need to work with some database queries for transaction.