2017-01-29 33 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

这是行不通的 –