-1

私は JavaScript で条件を書き留めました。下向き矢印の場合はデータベースを更新しますが、現在は JavaScript 条件に該当せず、サーバー レベルでデータベースを更新しています。どんな助けでも大歓迎です。

コード:

<script language="javascript">
    $(document).ready(function() {

        totalgames=<?= $totalgames ?>;

        //scoress = 0;
        previous_s=0;

        for(xx=totalgames; xx>=1; xx--){

            score_ele = 'scores'+xx;
            tdid_ele = 'tdid'+xx;
            var tdd = document.getElementById(tdid_ele);
            var scoress = document.getElementById(score_ele);

            if(previous_s == 0){
                tdd.innerHTML = "<img src='images/bullet.png'/>";
            }else{
                if(parseFloat(previous_s) > parseFloat(scoress.value)){
                    tdd.innerHTML = "<img src='images/arrow_up.png'/>";
                }else if(parseFloat(previous_s) < parseFloat(scoress.value)){
                    tdd.innerHTML = "<img src='images/arrow_down.png'/>";
                    <?php
                        //Selecting from table teams
                        $sql_sel_amnt = "Select * from teams where t_name='".$t_name."'";
                        $result_sel = $db1->getResult($sql_sel_amnt);
                        $row_sel = mysql_fetch_assoc($result_sel);

                        //Selecting from table profitnloss
                        $sql_pnl = "Select * from profitnloss where t_name='".$t_name."' and username='".$abc."'";
                        $result_pnl = $db1->getResult($sql_pnl);
                        $row_pnl = mysql_fetch_assoc($result_pnl);

                        $transact_money = $row_pnl['pnl_amount'];
                        $pnl_results = $row_pnl['pnl'];

                        $profit = 0;
                        $loss = 0;

                        $transact_money = explode("|", $transact_money);
                        $pnl_results = explode("|", $pnl_results);
                        for($i=0; $i<count($transact_money); $i++){
                            if($pnl_results[$i]=='P'){
                                $profit = $profit + $transact_money[$i];
                            }else{
                                $loss = $loss + $transact_money[$i];
                            }//end if
                        }//end for..
                        $money_results_total = $profit - $loss;

                        $pnl_date = date("d-m-Y H:i:s");
                        $pnl_amount = $row_sel['c_amount'];//total amount lost
                        $t_amount = $money_results_total + $row_pnl['t_amount'] + $pnl_amount;

                        $noofplayers = mysql_num_rows($result_sel)-1;//total no of players
                        $company_share = 17;//charity percentage
                        $company_share_amnt = $company_share*$pnl_amount/100;
                        $pnl_amount_remaining = $pnl_amount - $company_share_amnt;
                        $charity = substr($row_sel['charity'], 0, 2);//charity percentage
                        $charity_amount = $charity*$pnl_amount_remaining/100;

                        $sharing_amount = $pnl_amount-$charity_amount-$company_share_amnt;
                        $pnl_profit = round($sharing_amount/$noofplayers, 2);

                        echo "noofplayers=> ".$noofplayers.", company_share=> ".$company_share.", company_share_amnt=> ".$company_share_amnt.", charity=> ".$charity."%, charity_amount=> ".$charity_amount.", sharing_amount=> ".$sharing_amount.", pnl_profit=> ".$pnl_profit;

                        $sql_updt_loss = "UPDATE profitnloss SET game_date = '".$serial_date."', pnl_date = CONCAT(pnl_date, '$pnl_date|'), pnl_amount = CONCAT(pnl_amount, '$pnl_amount|'), pnl = CONCAT(pnl, 'Loss|'), t_amount='".$t_amount."' where username='".$abc."' and t_name='".$t_name."'";
                        //echo $updt_pnl;
                        //$result_loss = $db1->getResult($sql_updt_loss);

                        $sql_updt_profit = "UPDATE profitnloss SET pnl_date = CONCAT(pnl_date, '$pnl_date|'), pnl_amount = CONCAT(pnl_amount, '$pnl_profit|'), pnl = CONCAT(pnl, 'Profit|') where username not like'".$abc."' and t_name='".$t_name."'";
                        //echo $updt_pnl;
                        //$result_profit = $db1->getResult($sql_updt_profit);
                    ?>
                }else if(parseFloat(previous_s) == parseFloat(scoress.value)){
                    tdd.innerHTML = "<img src='images/bullet.png'/>";
                }//end if
            }//end if 0..
            previous_s = document.getElementById(score_ele).value;

        }//end for

    })//emd document ready..
</script>
4

1 に答える 1