2017-01-29 35 views
-1

我有這樣的代碼,我想實現下面的Java腳本到這個PHP代碼,我需要EXCUTE的JavaScript即使這個PHP從名爲index.php的 任何幫助,請如何實現的JavaScript到PHP文件

<script type = "text/javascript"> 

     $('.estudent_id').click(function(){ 
      $student_id = $(this).attr('name'); 
      $('#edit_query').load('load_edit1.php?student_id=' + $student_id); 
     }); 
    }); 
</script> 

Check_data.php

<table id = "table" class = "table table-bordered"> 

<?php 
$dtpickerdate = isset($_POST['dtpickerdate']) ? $_POST['dtpickerdate'] : NULL; 

$q_customer = $conn->query 
          ("SELECT * from orders inner JOIN customer_order on customer_order.order_no =orders.order_no and orders.date like'$dtpickerdate' inner join driver_order on driver_order.order_no=orders.order_no LEFT JOIN customer on customer.phone=customer_order.phone order by k_time,time desc") 
or die(mysqli_error()); 

$k_time = ''; 
while($f_customer = $q_customer->fetch_array()){ 
$s=mysqli_num_rows($q_customer); 
?> 
    <tr> 
<?php 

    if($k_time == '' || $k_time != $f_customer['k_time']){ 
    $k_time = $f_customer['k_time']; 
    echo '<td align="center" > <span style=" font-weight:bold;">' 
    .$f_customer['k_time']. '</td>'; 
     } else{ 
     echo "<td td style=' border: none;'>&nbsp;</td>"; 
     } 
     echo "<td style='background-color: #5f5d5d; ' align='center' span style='font-weight:bold;'> <a href = '#' style='color:#ececec;font-weight:bold;' data-toggle = 'modal' data-target = '#action'>".$f_customer['order_no']."</a></td>"; 

    echo "<td style='background-color: #5f5d5d;color:#ececec;'>" .$f_customer['first_name']."</td>"; 
    echo "<td style='background-color: #5f5d5d;color:#ececec;'>". 
} 
+0

您的問題的地址不明確。請重新說明它並提及你的目標是什麼。 –

+0

你的意思是這個頁面'check_data.php'將包含在你的'index.php'文件中?對 ? –

+0

@Usman Rana我有index.php哪些只有datepicker和這個datepicker調用另一個頁面(check_data.php)現在在check_data我需要執行一些JavaScript代碼,但我不知道他們爲什麼沒有工作,他們只能在index.php –

回答

0

呼應在正確的地方在你的PHP文件(S)的JavaScript應該工作:

<?php echo "<script type = 'text/javascript'>$('.estudent_id').click(function(){$student_id = $(this).attr('name');$('#edit_query').load('load_edit1.php?student_id=' + $student_id);});</script>"; ?> 

如果你想在多個文件中使用這個javascript,你可以將上面的內容保存爲一個PHP文件,例如myscript.php,然後將它包含在你希望代碼出現並運行的每個文件中:

<?php include('myscript.php'); ?> 
+0

解析錯誤:語法錯誤,意外'=',期待::(T_PAAMAYIM_NEKUDOTAYIM)在... –

+0

這是行不通的! –

+0

你的JS代碼有一個錯誤,我沒有檢查:一個額外的)};在關閉腳本標記之前。我更新了我的答案以將其刪除。現在就試試。 –

0

可以呼應JS這樣的:

<?php echo "<script type='text/javascript'>$('.estudent_id').click(function()  {$student_id = $(this).attr('name');$('#edit_query').load('load_edit1.php?student_id=' + $student_id);});});</script>"; ?> 
+0

但這個錯誤怎麼樣 意外的'=',期待 –

+0

@GhadahSalman我看到布拉德K爲回答/解決了你的問題。 –

+0

沒有它的不工作,因爲頁面沒有出現在瀏覽器中..頁面包含JavaScript被腳本調用索引,以便不執行JavaScript –

1

只需添加腳本PHP之外,你在做的HTML。 例如在你的代碼中放入這樣的東西。 這對您有幫助...

<script type = "text/javascript"> 
    $('.estudent_id').click(function(){ 
     $student_id = $(this).attr('name'); 
     $('#edit_query').load('load_edit1.php?student_id=' + $student_id); 
    }); 
</script> 
<table id = "table" class = "table table-bordered"> 
<?php 
$dtpickerdate = isset($_POST['dtpickerdate']) ? $_POST['dtpickerdate'] : NULL; 

$q_customer = $conn->query 
          ("SELECT * from orders inner JOIN customer_order on customer_order.order_no =orders.order_no and orders.date like'$dtpickerdate' inner join driver_order on driver_order.order_no=orders.order_no LEFT JOIN customer on customer.phone=customer_order.phone order by k_time,time desc") 
or die(mysqli_error()); 

$k_time = ''; 
while($f_customer = $q_customer->fetch_array()){ 
$s=mysqli_num_rows($q_customer); 
?> 
    <tr> 
<?php 

    if($k_time == '' || $k_time != $f_customer['k_time']){ 
    $k_time = $f_customer['k_time']; 
    echo '<td align="center" > <span style=" font-weight:bold;">' 
    .$f_customer['k_time']. '</td>'; 
     } else{ 
     echo "<td td style=' border: none;'>&nbsp;</td>"; 
     } 
     echo "<td style='background-color: #5f5d5d; ' align='center' span style='font-weight:bold;'> <a href = '#' style='color:#ececec;font-weight:bold;' data-toggle = 'modal' data-target = '#action'>".$f_customer['order_no']."</a></td>"; 

    echo "<td style='background-color: #5f5d5d;color:#ececec;'>" .$f_customer['first_name']."</td>"; 
    echo "<td style='background-color: #5f5d5d;color:#ececec;'>". 
} 
+0

這是行不通的 –