SELECTING ONLY SUMMED UP ROWS AND UPDATE IF CRITERIA IS MET

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
jonah
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Aug 12, 2017 8:35 am

Sat Aug 12, 2017 11:19 pm

if (isset($_POST['buyproduct']))
{ $ego=is price he is paying
$pa =mysqli_query($link,"SELECT SUM(amount_r) FROM products WHERE gh_pro=3 AND amount_r!=0 AND plock=1 AND match_t=2")or die(mysqli_error($link));
($fetch =mysqli_fetch_array($pa));{
$sum1=$fetch[0];
}
I Need this query to sum all amount in the table that equals, lesss and or more than the amount he is paying
$pa1 =mysqli_query($link,"SELECT COUNT(*) FROM products WHERE gh_pro=3 AND amount_r!=0 AND plock=1 AND match_t=2")or die(mysqli_error($link));
($fet =mysqli_fetch_row($pa1));{
$scount=$fet[0];
}
Want to count the number of rows where in the table that equals, lesss and or more than the amount he is paying
if($sum1!=0 AND $sum1==$ego OR $sum1!=0 AND $sum1>$ego OR $sum1!=0 AND $sum1<$ego){
$cr = mysqli_query($link,"SELECT * FROM products WHERE gh_pro=3 AND amount_r!=0 GROUP BY id") or die(mysqli_error($link));
($row = mysqli_fetch_assoc($cr));
foreach ($cr AS $row) {
$sid1=$row['nribama']; $sui=$row['user_id']; $sar=$row['amount_r']; $trs=$row['trans_id'];
What i intend doing here is to select all rows each that has product to sell and the money to be paid. i.e John wants to buy some particular products of $50,000 but in the table Jane, michael, fred, angela have products worth $20,000 , $20,000 , $40,000 , $5,000 respectively. What i want is to select all the rows john can pay and update John's amount to them which means John pays Jane $20,000 , Michael $20,000 , Fred $10,000 and balances updated as follows; Jane $0, Michael $0, Fred $40,000 and John the payer his balance of what he paid which means of John paid equal to what he is buying his balance will be $0 else is he pays less his balance will be what is remaining
if($sum1>$ego && $scount==1) $balance=$sar-$ego; elseif($sum1>$ego && $scount>1) $balance=$sar-$ego;
if($sum1<$ego && $scount==1) $balance=$sar-$sar; elseif($sum1<$ego && $scount>1) $balance=$sar-$sar;
if($sum1==$ego && $scount==1) $balance=$sar-$sar; elseif($sum1==$ego && $scount>1) $balance=$sar-$sar;
if($sum1>$ego && $scount==1) $apu=$ego; elseif($sum1>$ego && $scount>1) $apu=$ego-$sar;
if($sum1==$ego && $scount==1) $apu=$ego; elseif($sum1==$ego && $scount>1) $apu=$sar;
if($sum1<$ego && $scount==1) $apu=$sar; elseif($sum1<$ego && $scount>1) $apu=$sar;
if($sum1<$ego && $scount==1) $rempay=$ego-$sum1; elseif($sum1<$ego && $scount>1) $rempay=$ego-$sum1;
if($sum1>$ego && $scount==1) $rempay=$ego-$ego; elseif($sum1>$ego && $scount>1) $rempay=$ego-$ego;
if($sum1==$ego && $scount==1) $rempay=$ego-$sum1; elseif($sum1==$ego && $scount>1) $rempay=$ego-$sum1;
This place check his balance and that of those receiving payment for products and what john need to pay and to who
//$tax=$ego*5/100;
$query=mysqli_query($link,"INSERT INTO `products2`(`id`,`producttype`,`c_status`,`dtr_id`,`a_to_paid`,`ritrans`,`payre`,`purchase_time`,`expired`) VALUES ('$personal','$cplan','1','$ctid','$apu','$trs','$sui',NOW(),'$expiring')") or die(mysqli_error($link));
Insert the selected sellers john has to pay into products 2 table
////UPDATE RECEIVERS
$update=mysqli_query($link,"UPDATE products2 SET amount_r='$balance' WHERE id='$sid1'") or die(mysqli_error($link));
UP the balance of those to be paid
$ctn=mysqli_query($link,"SELECT COUNT(*) FROM products2 WHERE id='$personal' AND c_status=1") or die (mysqli_error($link));
$cd1 = mysqli_fetch_array($ctn);
$pcount= $cd1[0];
$query=mysqli_query($link,"UPDATE products SET payto='$pcount',rem_pay='$rempay' WHERE nribama='$cid'") or die(mysqli_error($link)); }}}
Counts the number of persons john have to pay and then updates his product table including if he has a refund balance to his rem_pay(remaining to pay)
PLEASE I REALLY NEED HELP ON THIS

Post Reply