Cannot use object of type MysqlResultSet - php

i had a problem in php install.php file
Cannot use object of type MysqlResultSet
i dont know why is my code not working
and this is my code
$this->provider->executeQuery('INSERT INTO perfect SET type="kings", name="%s", email="%s", points="%s", p_date="%s"',
array($get_players['name'], $get_players['email'], 0, date('Y.m.d'))
);
any idea ?

full code is
public function _isperfect()
{
// attackers
$count_attackers = 0;
$attackers_points = 0;
$attackers = $this->provider->fetchResultSet( "SELECT points FROM perfect WHERE type='attackers' ORDER BY points DESC LIMIT 3");
while ( $attackers->next( ) )
{
$attackers_points = $attackers->row['points'];
$count_attackers++;
}
if($count_attackers < 3)
{
$attackers_points = 0;
}
$get_players = $this->provider->fetchResultSet('SELECT name, email, attack_points FROM p_players WHERE attack_points > %s', array($attackers_points));
while ( $get_players->next( ) )
{
$get_att = $this->provider->fetchRow("SELECT points FROM perfect WHERE type='attackers' && email='". $get_players->row['email'] ."'");
if($get_att != NULL && $get_att['points'] < $get_players->row['attack_points'])
{
$this->provider->executeQuery('DELETE FROM perfect WHERE type="attackers" && email="'. $get_players->row['email'] .'"');
}
if($get_att['points'] < $get_players->row['attack_points'] || $get_att == null)
{
$this->provider->executeQuery('INSERT INTO perfect SET type="attackers", name="%s", email="%s", points="%s", p_date="%s"',
array($get_players->row['name'], $get_players->row['email'], $get_players->row['attack_points'], date('Y.m.d'))
);
}
}
$att = 0;
$attack = $this->provider->fetchResultSet( "SELECT points FROM perfect WHERE type='attackers' ORDER BY points DESC LIMIT 3");
while ( $attack->next( ) )
{
$att = $attack->row['points'];
}
$this->provider->executeQuery('DELETE FROM perfect WHERE points < %s && type="attackers"', array($att));
// end attackers
// defenders
$count_defenders = 0;
$defenders_points = 0;
$defenders = $this->provider->fetchResultSet( "SELECT points FROM perfect WHERE type='defenders' ORDER BY points DESC LIMIT 3");
while ( $defenders->next( ) )
{
$defenders_points = $defenders->row['points'];
$defenders_points++;
}
if($count_defenders < 3)
{
$defenders_points = 0;
}
$get_players = $this->provider->fetchResultSet('SELECT name, email, defense_points FROM p_players WHERE defense_points > %s', array($defenders_points));
while ( $get_players->next( ) )
{
$get_def = $this->provider->fetchRow("SELECT points FROM perfect WHERE type='defenders' && email='". $get_players->row['email'] ."'");
if($get_def != NULL && $get_def['points'] < $get_players->row['defense_points'])
{
$this->provider->executeQuery('DELETE FROM perfect WHERE type="defenders" && email="'. $get_players->row['email'] .'"');
}
if($get_def['points'] < $get_players->row['defense_points'] || $get_def == null)
{
$this->provider->executeQuery('INSERT INTO perfect SET type="defenders", name="%s", email="%s", points="%s", p_date="%s"',
array($get_players->row['name'], $get_players->row['email'], $get_players->row['defense_points'], date('Y.m.d'))
);
}
}
$def = 0;
$defend = $this->provider->fetchResultSet( "SELECT points FROM perfect WHERE type='defenders' ORDER BY points DESC LIMIT 3");
while ( $defend->next( ) )
{
$def = $defend->row['points'];
}
$this->provider->executeQuery('DELETE FROM perfect WHERE points < %s && type="defenders"', array($def));
// end defenders
// empires
$count_empires = 0;
$empires_points = 0;
$empires = $this->provider->fetchResultSet( "SELECT points FROM perfect WHERE type='empires' ORDER BY points DESC LIMIT 3");
while ( $empires->next( ) )
{
$empires_points = $empires->row['points'];
$count_empires++;
}
if($count_empires < 3)
{
$empires_points = 0;
}
$get_players = $this->provider->fetchResultSet('SELECT name, email, total_people_count FROM p_players WHERE total_people_count > %s', array($empires_points));
while ( $get_players->next( ) )
{
$get_emp = $this->provider->fetchRow("SELECT points FROM perfect WHERE type='empires' && email='". $get_players->row['email'] ."'");
if($get_emp != NULL && $get_emp['points'] < $get_players->row['total_people_count'])
{
$this->provider->executeQuery('DELETE FROM perfect WHERE type="empires" && email="'. $get_players->row['email'] .'"');
}
if($get_emp['points'] < $get_players->row['total_people_count'] || $get_emp == null)
{
$this->provider->executeQuery('INSERT INTO perfect SET type="empires", name="%s", email="%s", points="%s", p_date="%s"',
array($get_players->row['name'], $get_players->row['email'], $get_players->row['total_people_count'], date('Y.m.d'))
);
}
}
$emp = 0;
$empir = $this->provider->fetchResultSet( "SELECT points FROM perfect WHERE type='empires' ORDER BY points DESC LIMIT 3");
while ( $empir->next( ) )
{
$emp = $empir->row['points'];
}
$this->provider->executeQuery('DELETE FROM perfect WHERE points < %s && type="empires"', array($emp));
// end empires
// looters
$count_looters = 0;
$looters_points = 0;
$looters = $this->provider->fetchResultSet( "SELECT points FROM perfect WHERE type='looters' ORDER BY points DESC LIMIT 3");
while ( $looters->next( ) )
{
$looters_points = $looters->row['points'];
$count_looters++;
}
if($count_looters < 3)
{
$looters_points = 0;
}
$get_players = $this->provider->fetchResultSet('SELECT name, email, thief_points FROM p_players WHERE thief_points > %s', array($looters_points));
while ( $get_players->next( ) )
{
$get_loo = $this->provider->fetchRow("SELECT points FROM perfect WHERE type='looters' && email='". $get_players->row['email'] ."'");
if($get_loo != NULL && $get_loo['points'] < $get_players->row['thief_points'])
{
$this->provider->executeQuery('DELETE FROM perfect WHERE type="looters" && email="'. $get_players->row['email'] .'"');
}
if($get_loo['points'] < $get_players->row['thief_points'] || $get_loo == null)
{
$this->provider->executeQuery('INSERT INTO perfect SET type="looters", name="%s", email="%s", points="%s", p_date="%s"',
array($get_players->row['name'], $get_players->row['email'], $get_players->row['thief_points'], date('Y.m.d'))
);
}
}
$loo = 0;
$loote = $this->provider->fetchResultSet( "SELECT points FROM perfect WHERE type='looters' ORDER BY points DESC LIMIT 3");
while ( $loote->next( ) )
{
$loo = $loote->row['points'];
}
$this->provider->executeQuery('DELETE FROM perfect WHERE points < %s && type="looters"', array($loo));
// end looters
// kings
$end_server = $this->provider->fetchRow( "SELECT win_pid, game_over FROM `g_settings`");
$end_server_player = $this->provider->fetchRow( 'SELECT `name`,`email` FROM `p_players` WHERE id='.$end_server['win_pid'].' ');
if($end_server_player != null)
{
$this->provider->executeQuery('INSERT INTO perfect SET type="kings", name="%s", email="%s", points="%s", p_date="%s"',
array($get_players['name'], $get_players['email'], 0, date('Y.m.d'))
);
}
}

Related

Sum from column score if column score calculating from other column

Hello I have a table KPI and I want to calculate the final score from this category perspective in KPI (see image)
I script manually to keep the score column dynamic update, but I need to script total score to make my bar gauges up and down automatic.
This is my some code:
$kc= mysql_query("SELECT * FROM kpidetindv WHERE
idCat='3' AND year='$yr' AND vis='0' AND idEmp='$np' ORDER BY code ASC");
While ($kc2= mysql_fetch_assoc($kc))
{
$ikdi = $kc2['idKpiDetIndv'];
$ic = $kc2['idCat'];
$iu = $kc2['idUnit'];
$ictg= mysql_query("select * from `kpicat` where idCat='$ic'") or die(mysql_error());
$ictg2= mysql_result($ictg, 0, 'code');
$imt= mysql_query("select * from `kpiunit` where idUnit='$iu'") or die(mysql_error());
$imt2= mysql_result($imt, 0, 'code');
$imt3= mysql_result($imt, 0, 'symbol');
$sum = mysql_query("SELECT sum(actual) FROM monthkpimontindv WHERE idKpiDetIndv='$ikdi'") or die(mysql_error());
while ($row = mysql_fetch_array($sum)) {
$mkmi= $row['sum(actual)']; }
if ($mkmi=='') { $mkmi2='0';} else { $mkmi2=$mkmi; }
$tg= $kc2['target'];
$scr= $mkmi/$tg;
$scr2= number_format($scr * 100, 0);
$wgh= $kc2['weight'];
$scr3= $scr2*$wgh/100;
$trd= mysql_query("select * from `monthkpimontindv` where idKpiDetIndv='$ikdi' order by idMontIndv desc limit 1") or die(mysql_error());
$trd2= mysql_result($trd, 0, 'actual');
$trd3= mysql_query("select * from `monthkpimontindv` where idKpiDetIndv='$ikdi' order by idMontIndv desc limit 1,1") or die(mysql_error());
$trd4= mysql_result($trd3, 0, 'actual');
if ($trd2 > $trd4 ) { $trd5="trendup.png"; }
else if ($trd2 < $trd4 ) { $trd5="trenddown.png"; }
else if ($trd2 == $trd4 ) { $trd5="trendnet.png"; }
echo '<tr>';
echo '<td>'.$kc2['code'];
echo '<td>'.$kc2['title'].'';
echo '<td>'.number_format($kc2['target']).' '.$imt3;
echo '<td>'.number_format($mkmi2).' '.$imt3;
echo '<td>'.$kc2['weight'];
echo '<td>'.number_format($scr3, 0);
echo '<td class="text-center"><img class=user-avatar src=assets/img/'.$trd5.'>';
echo '<td class="text-center"><i class="fa-edit s16"></i> | </i>';
<?PHP
$kc= mysql_query("SELECT * FROM kpidetindv WHERE idCat='$qki7' AND year='$yr' AND vis='0' AND idEmp='$np' ORDER BY code ASC");
While ($kc2= mysql_fetch_assoc($kc))
{
$sum = mysql_query("SELECT sum(actual) FROM monthkpimontindv WHERE idKpiDetIndv='$q'") or die(mysql_error());
while ($row = mysql_fetch_array($sum)) {
$mkmi= $row['sum(actual)']; }
if ($mkmi=='') { $mkmi2='0';} else { $mkmi2=$mkmi; }
$tg= $kc2['target'];
$scr= $mkmi/$tg;
$scr2= number_format($scr * 100, 0);
$wgh= $kc2['weight'];
$scr3= $scr2*$wgh/100;
$fscr+= number_format($scr3, 0);
}
if ($fscr == 0) { $imgs="speedo.png";}
else if ($fscr <= 10 ) { $imgs="speedo1.png";}
else if ($fscr <= 20 ) { $imgs="speedo2.png";}
else if ($fscr <= 30 ) { $imgs="speedo3.png";}
else if ($fscr <= 40 ) { $imgs="speedo4.png";}
else if ($fscr <= 50 ) { $imgs="speedo5.png";}
else if ($fscr <= 60 ) { $imgs="speedo6.png";}
else if ($fscr <= 70 ) { $imgs="speedo7.png";}
else if ($fscr <= 80 ) { $imgs="speedo8.png";}
else if ($fscr <= 90 ) { $imgs="speedo9.png";}
else if ($fscr <= 1000 ) { $imgs="speedo10.png";}
?>

MySQL Join Queries

I've been given this code to work with, and I know that mysql_* is deprecated, but I'm trying to figure out a way to join all of these queries, because these while loops and queries are hogging resources and killing load time. Any suggestions?
$result2 = mysql_query("SELECT * FROM tblOperators WHERE (Team = 'SALES' OR Team = 'RENEWALS' OR Team = 'CSR') AND OperatorLocale='USA' AND OperatorStatus='ACTIVE'");
while ($row2 = mysql_fetch_array($result2)) {
$operID = $row2['OperatorID'];
$result = mysql_query("SELECT * FROM tblUserPayments WHERE OperatorID = '$operID' AND PaymentStatus='OK' AND PaymentDate LIKE '$currentDate%'");
while ($row = mysql_fetch_array($result)) {
if ($row['PaymentReason'] == 'ACTIVATION') {
$ActvCount++;
if ($row['PaymentMethod'] == 'CREDITCARD' || $row['PaymentMethod'] == 'PAPERCHECK') {
$ActvUpgrade += $row['ChargeAmount'];
}
} elseif ($row['PaymentReason'] == 'UPGRADE') {
$userid = $row['UserID'];
$paymentdate = $row['PaymentDate'];
$result1 = mysql_query("SELECT * FROM tblRenewalInvoices WHERE UserID='$userid' AND ('$paymentdate' >= DATE_SUB(DueDate, INTERVAL 90 DAY) AND '$paymentdate' < DATE_ADD(DueDate, INTERVAL 15 DAY)) AND ParentInvoiceID IS NULL ORDER BY InvoiceNum DESC LIMIT 1");
if ($row1 = mysql_fetch_array($result1)) {
$packageid = $row['PackageID'];
$pack = mysql_query("SELECT * FROM tblUserPackages WHERE PackageID='$packageid';");
if ($pack1 = mysql_fetch_array($pack)) {
$expDate = $pack1['ExpirationDate'];
$dueDate = $row1['DueDate'];
$days = mysql_fetch_row(mysql_query("SELECT TO_DAYS('$expDate')-TO_DAYS('$dueDate');"));
$months = (int) (((int) $days + 14) / 30.4);
$years = (int) (((int) $days + 182) / 365);
$Intervals = 0;
if ($years > 0) {
$Intervals = $years;
} if (($pack1['Package'] or 'GPS-SVL') or ($pack1['Package'] == 'GPS-1') or ($pack1['Package'] == 'GPS-1PLUS')) {
if ($Intervals > 1) {
if ($row['PaymentMethod'] == 'CREDITCARD' || $row['PaymentMethod'] == 'PAPERCHECK') {
$renewalCount++;
$Actv += $row['ChargeAmount'];
}
} else {
if ($row['PaymentMethod'] == 'CREDITCARD' || $row['PaymentMethod'] == 'PAPERCHECK') {
$renewalCount++;
$ActvRenewal += $row['ChargeAmount'];
}
}
} else {
$renewalCount++;
$Actv += $row['ChargeAmount'];
}
} else {
}
} else {
if ($row['PaymentMethod'] == 'CREDITCARD' || $row['PaymentMethod'] == 'PAPERCHECK')
$ActvUpgrade += $row['ChargeAmount'];
}
} elseif ($row['PaymentReason'] == 'ADDVEHICLE') {
if ($row['PaymentMethod'] == 'CREDITCARD' || $row['PaymentMethod'] == 'PAPERCHECK')
$ActvVehicleAdds += $row['ChargeAmount'];
}
}
$result = mysql_query("SELECT * FROM tblRenewalCalls WHERE OperatorID = '$operID' AND PayStatus='OK' AND DateSubmitted LIKE '$currentDate%'");
while ($row = mysql_fetch_array($result)) {
if ($row['Charged']) {
if ((int) $row['RenewYears'] > 1) {
$renewalCount++;
$Actv += $row['RenewTotal'];
} else {
$renewalCount++;
$ActvRenewal += $row['RenewTotal'];
}
}
}
} if ($ActvCount != 0) {
$PerActv = ($ActvUpgrade + $ActvVehicleAdds) / $ActvCount;
} else {
$PerActv = 0;
}
$total = $Actv + $ActvRenewal + $ActvUpgrade + $ActvVehicleAdds;
// Fix to show proper renewal dollars
$ActvRenewal = $total - ($ActvVehicleAdds + $ActvUpgrade);
$AvgRenewal = ($ActvRenewal) / $renewalCount;
$upgradeEarned = $ActvUpgrade;
$renewalEarned = $ActvRenewal;
Here is my code so far for the joined query, but it's not correct because I am still missing certain bits of information. It is much faster for mysql to handle the mathematics, than for the database to pass the information to php, then have php process it. I'm just not sure as to how to approach this:
$result = mysql_query(
"SELECT p.PaymentReason AS PaymentReason,
p.PaymentMethod AS PaymentMethod,
p.ChargeAmount AS ChargeAmount,
p.UserID AS UserID,
p.PaymentDate AS PaymentDate,
r.PackageID AS PackageID
FROM tblOperators AS o JOIN tblUserPayments AS p JOIN tblRenewalInvoices
AS r JOIN tblUserPackages AS k JOIN tblRenewalCalls
AS c ON o.OperatorID=p.OperatorID
AND r.UserID=p.UserID AND r.PaymentDate=p.PaymentDate
AND r.PackageID=k.PackageID
WHERE (o.Team='SALES' OR o.Team='RENEWALS' OR o.Team='CSR') AND
o.OperatorLocale='USA' AND
o.OperatorStatus='ACTIVE' AND
p.PaymentStatus='OK' AND
p.PaymentDate LIKE '$currentDate%'");
Any help is greatly appreciated.
Try this:: You have missed the JOIN Criteria for Table tblRenewalCalls
SELECT p.PaymentReason AS PaymentReason,
p.PaymentMethod AS PaymentMethod,
p.ChargeAmount AS ChargeAmount,
p.UserID AS UserID,
p.PaymentDate AS PaymentDate,
r.PackageID AS PackageID
FROM tblOperators AS o
JOIN tblUserPayments AS p ON o.OperatorID=p.OperatorID
JOIN tblRenewalInvoices AS r ON r.UserID=p.UserID AND r.PaymentDate=p.PaymentDate
JOIN tblUserPackages AS k ON r.PackageID=k.PackageID
JOIN tblRenewalCalls AS c // JOIN CRITERIA
WHERE (o.Team='SALES' OR o.Team='RENEWALS' OR o.Team='CSR') AND
o.OperatorLocale='USA' AND
o.OperatorStatus='ACTIVE' AND
p.PaymentStatus='OK' AND
p.PaymentDate LIKE '$currentDate%'")

Sum values in each group with a loop

I have a while loop that gives this result:
Userid Point
1 10
1 15
2 5
2 10
3 8
3 2
How can I sum the userid points and output with highest number first, like this:
Userid Point
1 25
2 20
3 10
Is there any "foreach", "for" or any other method that can accomplish such result?
The code:
include ('variables.php');
//Fetch data from matchdata table
$q = "SELECT userid, matchid, homescore, awayscore FROM predictiondata ORDER BY userid ASC";
$r = mysqli_query($mysqli, $q);
while ($row = mysqli_fetch_array($r)) {
//Define predictions
$predhome = $row['homescore'];
$predaway = $row['awayscore'];
//Fetch gameresults
$qres = "SELECT id, homescore, awayscore, bonuspoints FROM matches WHERE id = ".$row['matchid']."";
$rres = mysqli_query($mysqli, $qres);
$result = mysqli_fetch_array($rres);
$homescore = $result['homescore'];
$awayscore = $result['awayscore'];
$bonus = $result['bonuspoints'];
$id = $result['id'];
//Calculate points
if ($homescore == $predhome && $awayscore == $predaway && $homescore != '') { $result_point = $correct_score + $correct_result + $correct_number + $correct_number; }
else if ($homescore == $predhome && $awayscore != $predaway OR $homescore != $predhome && $awayscore == $predaway) { $result_point = $correct_result + $correct_number; }
else if ($predhome > $predaway && $homescore > $awayscore OR $predhome < $predaway && $homescore < $awayscore) { $result_point = $correct_result; }
else if (is_null($predhome) OR $homescore == '') { $result_point = 0; }
else { $result_point = 0; }
if ($homescore == $predhome && $awayscore == $predaway && $homescore != '') { $bonus = $bonus; }
else if (is_null($predhome) OR $homescore == '') { $bonus = 0; }
else { $bonus = 0; }
if (is_null($predhome) OR $homescore == '') { $total_point = 0; }
else { $total_point = $result_point + $bonus; }
//Calculate total round sum
$total_roundsum = $result_point + $bonus;
//echo $username.' - '.$total_roundsum.'<br />';
if($total_roundsum != 0) {
echo $row['userid']. ' - ' .$total_roundsum.'<br />';
}
}
At the moment, the code only echo's the results.
The "variables.php" holds the $correct_score + $correct_result + $correct_number variables.
Assuming the two columns are an associated array -- $users_and_points.
$points_array = array();
foreach ( $users_and_points as $user_id => $point ) {
if( !isset( $points_array[$user_id] ) {
$points_array[$user_id] = 0;
}
$points_array[$user_id] += $point;
}
// newly associated array with calculated totals
$points_array;
Update
Based on your code above instead of echoing build an array of users and points.
echo $row['userid']. ' - ' .$total_roundsum.'<br />';
can be replaced with:
if( !isset( $points_array[$row['userid']] ) {
$points_array[$row['userid']] = 0;
}
$points_array[$row['userid']] += $total_roundsum;
That will give you an associated array of user ids and associated points.
print_r( $points_array );
Note: Set the variable before your loop. Example, $points_array = array();

SQL: Unix Timestamp entrys with Zero

i misunderstand why my query gives me entrys with an Timestamp of 0. Can anyone say me what im doing wrong?
Query:
SELECT
*
FROM
`changes`
WHERE
`time_from`>=1393628400
AND
`time_to`<=1394838000
AND
`area`='USERNAME'
ORDER BY
`time_from` DESC,
`time_to` DESC
PHP
$time_from = (isset($_POST['time_from']) ? strtotime($_POST['time_from']) : null);
$time_to = (isset($_POST['time_to']) ? strtotime($_POST['time_to']) : null);
if(empty($time_from) && empty($time_to)) {
/* Do Nothing */
} else {
if(!empty($time_from) && $time_from > 0 && !empty($time_to) && $time_to > 0) {
$query = sprintf(' `time_from`>=%d AND `time_to`<=%d', $time_from, $time_to);
} else if(!empty($time_from) && $time_from > 0) {
$query = sprintf(' `time_from`>=%d', $time_from);
} else if(!empty($time_to) && $time_to > 0) {
$query = sprintf(' `time_to`<=%d', $time_to);
}
$results = $wpdb->get_row(sprintf('SELECT COUNT(*) AS `count` FROM `%sarea_changes` WHERE%s AND `area`=\'%s\'', $wpdb->prefix, $query, $user->user_login));
$count = $results->count;
if($count < 10) {
$position = 0;
$has_more_pages = false;
}
$pages = ceil($count / $max_rows);
$query = sprintf('SELECT * FROM `%sarea_changes` WHERE%s AND `area`=\'%s\' ORDER BY `time_from` DESC, `time_to` DESC', $wpdb->prefix, $query, $user->user_login, $position, $max_rows);
print $query;
$entrys = $wpdb->get_results($query); // LIMIT %d, %d
}
POST Data:
time_from is 01.03.2014 and time_to is 15.03.2014
But i get following entrys (see the time_to), why is that 0 that dont match my Query?
Screenshot:
(Hidden data for privacy policy)

can anyone help me to replace this code snippet with better approach without using if elseif

In this code snippet ,all the values will be database driven and i need a better replacement for this code.
commission in percentage will be calculated based on the task price range.
$commission1=10;//in percentage
$commission2=20;
$commission3=30;
$taskprice =200;
if($taskprice >=0 && $taskprice <=150)
{
$adminearnings = ($taskprice *$commission1 ) / 100 ;
$Geniepayment = $taskprice - $adminearnings;
}
else if($taskprice >=151 && $taskprice <=300)
{
$adminearnings = ($taskprice * $commission2) / 100 ;
$Geniepayment = $taskprice - $adminearnings;
}
else if($taskprice >=301 && $taskprice <=450)
{
$adminearnings = ($taskprice * $commission3 ) / 100 ;
$Geniepayment = $taskprice - $adminearnings;
}
echo $taskprice.'</br>';
echo $adminearnings.'</br>';
echo $Geniepayment.'</br>';
As for me, I would make a simple function to have fast access to what you need :
function calculate($commission, $taskprice)
{
$arrayCommission = array(0, 10, 20, 30);
$adminearnings = ($taskprice * $arrayCommission[$commission] ) / 100 ;
$Geniepayment = $taskprice - $adminearnings;
return array($taskprice, $adminearnings, $Geniepayment);
}
That would be something like this:
if($taskprice >=0 && $taskprice <=150)
{
$arrayAnswer = calculate(1, $taskprice);
}
elseif($taskprice >=151 && $taskprice <=300)
{
$arrayAnswer = calculate(2, $taskprice);
}
elseif($taskprice >=301 && $taskprice <=450)
{
$arrayAnswer = calculate(3, $taskprice);
}
I agree with the others that the conditionals are required. I would refactor to pull out the calculation, something like this:
<?php
// Returns array(earnings, payment)
//
function getEarningsPayment($taskprice, $commission)
{
$earnings = ($taskprice * $commission) / 100 ;
$payment = $taskprice - $adminearnings;
return array ($earnings, $payment);
}
$commission1=10;//in percentage
$commission2=20;
$commission3=30;
$taskprice =200;
if($taskprice >=0 && $taskprice <=150)
$commission = $commission1;
else if($taskprice >=151 && $taskprice <=300)
$commission = $commission2;
else if($taskprice >=301 && $taskprice <=450)
$commission = $commission3;
list ($adminearnings, $Geniepayment) = getEarningsPayment($taskprice, $commission);
echo $taskprice.'</br>';
echo $adminearnings.'</br>';
echo $Geniepayment.'</br>';
?>
guys how about this idea ..waiting for your feedbacks and suggestions
$commissions = array
(
'0'=>array
(
"commission_start_range"=>"0","commission_end_range"=>"100","commission_amount"=>"10"
),
'1'=>array
(
"commission_start_range"=>"101","commission_end_range"=>"200","commission_amount"=>"20"
),
'2'=>array
(
"commission_start_range"=>"201","commission_end_range"=>"300","commission_amount"=>"30"
)
);
function check_commission($task_price,$commissions)
{
foreach($commissions as $commission_data)
{
$start = $commission_data['commission_start_range'];
$end = $commission_data['commission_end_range'];
$amount= $commission_data['commission_amount'];
if($task_price >=$start && $task_price <=$end)
{
$admin_earnings = ($task_price * $amount) / 100 ;
$genie_payment = $task_price - $admin_earnings;
return $admin_earnings;//echo $admin_earnings;
}
}
}
check_commission(200,$commissions);

Categories