Percentage, instead of float

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
SlapStick
Forum Newbie
Posts: 4
Joined: Thu Mar 10, 2011 3:30 pm

Percentage, instead of float

Post by SlapStick »

Thanks for your help with this, I just can't figure it out as I'm not experienced. I get white pages with the things I've tried.

I'm using a coupon modification for vbulletin and this is the function:

Code: Select all

$coupon_value = $vbulletin->db->query_first("
		SELECT couponvalue, couponname
			FROM " . TABLE_PREFIX . "coupons
			WHERE TO_DAYS(couponvalidto) - TO_DAYS(CURDATE()) > 0
			AND nouses > 0
			AND couponid = '$couponid'
			AND validfor LIKE '%$subscriptionid%'
		");					
		
		$newvalue = floatval($coupon_value['couponvalue']);
		$coupon_name = $coupon_value['couponname'];	

		$value = vb_number_format(($value - $newvalue), 2);
	}
	return $value;
This is the line I need to modify. Basically, I need it to calculate a percentage rather than a float value so it will apply evenly across all subscriptions rather than a flat amount.

Code: Select all

$newvalue = floatval($coupon_value['couponvalue']);
I've tried some different things but they've all wound up in white screens.

Thanks for your help.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Percentage, instead of float

Post by AbraCadaver »

Is couponvalue already meant to be a percentage in the database or is it an amount?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
SlapStick
Forum Newbie
Posts: 4
Joined: Thu Mar 10, 2011 3:30 pm

Re: Percentage, instead of float

Post by SlapStick »

I believe it is pulling a value from the database that you set when you create the coupons. It is just an amount in the database.

Image
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Percentage, instead of float

Post by AbraCadaver »

So in that example the 10.00 is 10%?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
SlapStick
Forum Newbie
Posts: 4
Joined: Thu Mar 10, 2011 3:30 pm

Re: Percentage, instead of float

Post by SlapStick »

AbraCadaver wrote:So in that example the 10.00 is 10%?
Well I want it to apply as a percentage. Currently the plugin is treating it as a flat value that comes off subscriptions. So if I have say, a 1 month option it takes $10 off of that, and a 3 month option that I may have set a lower price on will have $10 off too. Whereas if I use a pct it will come off each sub evenly.

Here is a reply from vbulletin.org where the developer says how to do it, but I don't understand how.

http://www.vbulletin.org/forum/showpost ... ostcount=9
SlapStick
Forum Newbie
Posts: 4
Joined: Thu Mar 10, 2011 3:30 pm

Re: Percentage, instead of float

Post by SlapStick »

Anyone else provide a pointer?
Post Reply