Calculation in php

hi peeps how do i do calculation in php mysql i can only do it in javascript but am getting limitation with something so i want to try php below is what am trying to achieve

bidtotal / bidtotalt1 * .95

.95 is also 5

// Retrieve  data for sum first to score
$query = "SELECT sum( AS bidtotal, sum(b.willwin = a.team1) AS bidtotalt1, s.teams AS teams1, a.team1 FROM " . $DBPrefix . "auctions a
        LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = a.team1)
        LEFT JOIN " . $DBPrefix . "bids_score_sumup b ON ( =
        WHERE = :auc_id ";
$params = array();
$params[] = array(':auc_id', $id, 'int');
$db->query($query, $params);
$AUCTION = $db->result();


        'TEAM_FTSSU_ONE' => htmlspecialchars($AUCTION['teams1']),
        'TOTAL_FTSSU_USER1' => htmlspecialchars($AUCTION['bidtotalt1']),
        'BIDTOTAL_FTSSU' => htmlspecialchars($AUCTION['bidtotal'])


i dont get what your problem is. at least the calculation is not in the code.

thats cause i dont know how to go about it

Are you hoping to do it as part of the query, or in the code after you have retrieved the data? For the latter, the syntax is so similar to JavaScript I am surprised you are having trouble with it. Can you show what you’ve tried?


1 Like

maybe you write it in the code.

I’m guessing this has to do with the percent code you were working on about a month ago.

If so, the logic is:

((part divided by whole) times 100) equals the percent the part is of the whole

When you multiply a number by .95 you will get 95% of that number, not 5%. To get 5% you would multiply the number by .05


bidtotal = 20 
bidtotalt1 = 100 
somepercent = bidtotal / bidtotalt1 * .95 

somepercent will be .19

Typo fixed :blush:

well using javascript this is what it looks like

 <div id="tsus1">
var x = ( {BIDTOTAL_FTSSU} / {TOTAL_FTSSU_USER1} ) * .95 ;
document.getElementById("tsus1").innerHTML = x;
                            ({TOTAL_FTSSU_USER1} users)</div>

Is that pure JavaScript, or is your platform dealing with the curly braces?

In any case, it’s basically the same in PHP except you have to prefix your variable names with a $ as you know. And obviously you’ll need to base it on the values in the $AUCTION array rather than the other ones. At it’d probably be easier to echo the value in the appropriate place rather than trying to insert the value after the page is drawn as the JS does.

its pure javascript my platform allows curly braces also.
i know am suppose to use calculation sign to run it in php but not sure where to start cause am gonna want to sumup the divide and then minus 5% from it just like that javascript

Given the comprehensive nature of the rest of your PHP code, I’m at a loss as to why you’re having so much trouble. Why not have a go at translating the calculation part of it to PHP and see how you go on?

ok i think i got it working with javascript funny how one can implement codes in codes thanks anyway

ended up looking like this

document.getElementById("ftssulowhigh1").innerHTML = ( {BIDTOTAL_FTSSU} / {TOTAL_FTSSU_USER1} ) * {HOUSE_COMMISSION} > {MINIMUM_BID} ? ' <div id="tsuscore1"></div>' : '{WILLMINBID}';
document.getElementById("tsuscore1").innerHTML = x;

looks weird but its k now to figure out how to add a comma cause it just out all numbers without a comma, how do i make that happen thansk

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.