Help me with PHP coding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mimic
Forum Newbie
Posts: 4
Joined: Thu Aug 01, 2013 3:49 am

Help me with PHP coding

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help me with PHP coding

Post by requinix »

Are you able to get that "number of transactions made" figure yet?
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

Re: Help me with PHP coding

Post 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
mimic
Forum Newbie
Posts: 4
Joined: Thu Aug 01, 2013 3:49 am

Re: Help me with PHP coding

Post by mimic »

Thanks a lot you guys! That is a Great Help. I will try with this.
haley01
Forum Newbie
Posts: 1
Joined: Wed Jun 19, 2013 6:11 am

Re: Help me with PHP coding

Post by haley01 »

Hello...I think you will need to work with some database queries for transaction.
Post Reply