簡體   English   中英

如果條件數組聲明錯誤在php和datatable代碼的輸入標簽內

[英]If condition array declaration error inside input tag for php and datatable code

我是PHP新手。 我正在嘗試修復PHP代碼的語法錯誤。 但似乎不起作用。 我在s [i] [4]遇到語法錯誤。 如果更改為“ + s [i] [4] +”,則不會抱怨語法錯誤,但不會讀取實際值。 我認為我在PHP代碼中使用了錯誤的變量,但是嘗試了很多方法但失敗了。 實際上,如果狀態(s [i] [4])被取消,我試圖隱藏付費按鈕。 請幫忙。

Java腳本代碼

`<script type="text/javascript">

            $(document).ready(function() {
                var table  = $('#myTransactionitems').dataTable();  //Initialize the datatable
                var user = $(this).attr('id');
                if(user != '') 
                { 
                    $.ajax({
                        url: 'transactions',
                        dataType: 'json',
                        success: function(s){
                            console.log(s);
                            table.fnClearTable();
                            for(var i = 0; i < s.length; i++) {
                                table.fnAddData([
                                    s[i][0],
                                    s[i][1],
                                    s[i][2],
                                    s[i][3],
                                    s[i][4],
                                    s[i][5],
                                    "<form method='post' action = 'donationSplit'><input name = 'donationid' type='hidden'\
                    value='"+s[i][0]+"'></input><input type='submit' value = 'Paid' <?php if (s[i][4]=='Cancelled'){ ?> style='display:none' <?php   } ?> class='btn btn-sm btn-success pull-left '>\
                   </input></form><form method='post' action = 'donationSplit'><input name = 'donationid' type='hidden' \
                    value='"+s[i][0]+"'></input><input type='submit' value = 'Cancel' class='btn btn-sm btn-danger pull-right'>\
                   </input></form>" 
                                ]);                                     
                            } // End For

                        },
                        error: function(e){
                            console.log(e.responseText);    
                        }
                    });
                }   
            });

        </script>`

Trasaction.php代碼

`

<?php
include('sessionstart.php');
include('session.php');
require_once("dbcontroller.php");
$db_handle = new DBController();
$user_id=$_SESSION['login_user_id'];
$query = mysql_query("select * from mytransactions_list where userid = '$user_id'");
while ($fetch = mysql_fetch_array($query)) {
    $output[] = array($fetch[0], $fetch[1], $fetch[2], $fetch[3], $fetch[4], $fetch[5], $fetch[6]);
}
echo json_encode($output);
?>
`

您不能在PHP中使用Javascript變量,因為首先執行PHP代碼。

嘗試這個

"<form method='post' action = 'donationSplit'>\
    <input name = 'donationid' type='hidden' value='"+s[i][0]+"' />\
    <input type='submit' value = 'Paid' " + (s[i][4]=='Cancelled') ? "style='display:none'" : "" + "class='btn btn-sm btn-success pull-left ' />\
</form>\
<form method='post' action = 'donationSplit'>\
    <input name = 'donationid' type='hidden' value='"+s[i][0]+"' />\
    <input type='submit' value = 'Cancel' class='btn btn-sm btn-danger pull-right' />\
</form>" 

下面的代碼應該可以正常工作。 我添加了一個名為disp1的JS變量。 分配的值為“ display:none;”。 如果滿足if條件,則為空。

for(var i = 0; i < s.length; i++) {
    var disp1 = '';
    if ( s[i][4] == 'Cancelled' ) {
        disp1 = 'display:none;'
    }
    table.fnAddData([
        s[i][0],
        s[i][1],
        s[i][2],
        s[i][3],
        s[i][4],
        s[i][5],
        "<form method='post' action = 'donationSplit'><input name = 'donationid' type='hidden'\
                    value='"+s[i][0]+"'></input><input type='submit' value = 'Paid' style='" + disp1 +"' class='btn btn-sm btn-success pull-left '>\
                   </input></form><form method='post' action = 'donationSplit'><input name = 'donationid' type='hidden' \
                    value='"+s[i][0]+"'></input><input type='submit' value = 'Cancel' class='btn btn-sm btn-danger pull-right'>\
                   </input></form>" 
                            ]);                                     
                            } // End For
                        },
                        error: function(e){
                            console.log(e.responseText);    
                        }
                    });
                }   
            });

內縮進

[英]Indentation inside of <?php tag with PHP Code Sniffer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM