0

EDIT: May I ask for assistance regarding this code?

This is my modal. My input text receives a value of AAA-123-0001

This script is being included into the main page via include()

<input type="hidden" class="decid" id="id" name="id">
<?php include 'includes/services_payslip_list_payslip-selection.php'; ?>

This is my services_payslip_list_payslip-selection.php

<script>
  $(document).ready(function() {
  $("#id").change(function() {
    var id = $(this).val();
    if(id != "") {
      $.ajax({
        url:"services_payslip_list-payslip-table.php",
        data:{id:id},
        type:'POST',
        success:function(response) {
          var resp = $.trim(response);
          $("#id").html(resp);
        }
      });
    }
  });
</script>

This is my services_payslip_list-payslip-table.php

<table id="example2" class="table table-bordered">
<thead>
<th>Schedule Date</th>
<th>Schedule Name</th>
<th>Recorded In</th>
<th>Recorded Out</th>
<th>Day Count</th>
<th>Day Value</th>
<th>N.D. Value</th>
<th>Leave Count</th>
<th>R.H. Count</th>
<th>R.H. Value</th>
</thead>
<tbody>

<?php 
include 'includes/session.php';
if(isset($_POST['id'])) {
$id=$_POST['id']
}
$user = $user['fingerscanno'];
$sql = "SELECT fingerscanno, scheduledate, schedulename, recordin, recordout, noofdays, rate, nightdifferential, leaveday, regularholiday, specialholiday, referenceno

FROM payrollrecords WHERE fingerscanno='$user' and referenceno='$id'";

                    $query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
                    while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){

 echo "
                        <tr>
                          <td>".$row['scheduledate']."</td>
                          <td>".$row['schedulename']."</td>
                          <td>".$row['recordin']."</td>
                          <td>".$row['recordout']."</td>
                          <td>".$row['noofdays']."</td>
                          <td>".$row['rate']."</td>
                          <td>".$row['nightdifferential']."</td>
                          <td>".$row['leaveday']."</td>
                          <td>".$row['regularholiday']."</td>
                          <td>".$row['specialholiday']."</td>
                        </tr>
                      ";
}

                  ?>
                </tbody>
              </table>

What seems to be the problem here? services_payslip_list_payslip-selection.php won't load into the modal.

pjustindaryll
  • 377
  • 3
  • 14
  • Do you mean without submitting the form to your PHP script? – showdev Jul 28 '19 at 08:39
  • @showdev yeah, is it possible? The modal is within the same page as the php arguement. I understand that ````document.getElementsByName()```` can capture that data, but I will just end up in a loop since I don't know how to capture that value and use it as a php argument within the same page. – pjustindaryll Jul 28 '19 at 08:42
  • 1
    One method is to use JavaScript to get the value from the `` and asynchronously send it to your PHP file. See [How to make an AJAX call without jQuery?](https://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery). Or, if you're using jQuery: [Pass value from html form to php without submitting the form](https://stackoverflow.com/questions/6065101/pass-value-from-html-form-to-php-without-submitting-the-form). – showdev Jul 28 '19 at 08:44
  • @showdev my problem is that the page does not reload again since the php query is inside a modal. – pjustindaryll Jul 28 '19 at 08:46
  • If you use AJAX, the page will not reload. – showdev Jul 28 '19 at 08:47
  • @showdev I'll check it, ill keep you posted. – pjustindaryll Jul 28 '19 at 08:51
  • Sounds good. Another useful reference is [Ajax @ MDN](https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX): "...web applications are able to make quick, incremental updates to the user interface without reloading the entire browser page." – showdev Jul 28 '19 at 08:53
  • @showdev No luck on the guides. My mail problem is that the SQL Query is within the same page as the modal. The flow goes like this: Main Page -> Load the modal without refreshing the page and the SQL Query is inside the modal. – pjustindaryll Jul 28 '19 at 09:17
  • I'd make a separate PHP file that receives a value, queries the database, and echos the results. Then, when you call it with AJAX, the results will be returned to that JavaScript call and you can display whatever you need. – showdev Jul 28 '19 at 09:24
  • @showdev I did some editing, based on AJAX, what seems to be the problem with the code? Please see above. – pjustindaryll Jul 28 '19 at 10:21
  • Do you get any errors? One issue might be that the [session can't be started after HTML has be outputted](https://stackoverflow.com/a/8812777/924299). Also, it seems that the `` will be replaced with a `` and I'm not sure if that's what's desired.
    – showdev Jul 29 '19 at 13:24
  • @showdev I think the main reason why this didn;t work is I'm trying to use the echo result as PHP parameter. – pjustindaryll Jul 30 '19 at 03:47

0 Answers0