Why is my script is only getting the first row of my php table? below is my code

Jericho Capuyan

This is my JavaScript code

$('input#name-submit').on('click', function() {
    var name = $('input#name-submit').val();
    if($.trim(name) != ''){
        $.post('getmodalreasonUT.php', {name: name}, function(data) {
            alert(data);
        });
    }
});

and this is my php code

<?php

if(isset($_POST['Pending'])){
    echo "<header class='panel-heading'> Undertime Pending</header>";
    echo "<table class='table table-bordered'>
    <thead>
    <tr class='tbl-record'>
    <th>ID</th>
    <th>Name of Employee</th>
    <th>Position</th>
    <th>Date Filed</th>
    <th>Number of hours</th>
    </tr>
    </thead>
    <tbody>";

    $sql =   "SELECT * FROM utrequestform WHERE user_eid = '$employeenumber' and check_managerandsspv = '0'";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {

        while($row = $result->fetch_assoc()){                             
            echo "<tr class='tbl-info text-center'>                            
            <td>".$row['user_eid']."</td>
            <td>".$row['nameofemployee']." </td>
            <td>".$row['position']."</td>
            <td>".$row['datefiled']."</td>
            <td>".$row['noofhours']."</td>    
            <td><input type='submit' id='name-submit' value='$row[id]'></td>
            </tr> ";

        }
    }else{
        echo "<tr><td colspan='10'>No pending UT request.</td></tr>";
    }
    echo "</tbody></table>";
}
?> 

This is my echo php code.

<?php 
    include ('connection.php');
    $please = $_POST['name'];
    echo $please;
?>

this is my database structure

Dan H

You are generating the HTML like this:

<input type='submit' id='name-submit' value='$row[id]'>

Which will render the same input several times with the same ID. This is invalid markup. You need to change that line for:

<input type='submit' id='name-submit-$row[id]' name='request-val' value='$row[id]'>

Then change your jQuery for:

$('input[name="request-val"]').on('click', function() {
    var name = $(this).val();
    if($.trim(name) != ''){
        $.post('getmodalreasonUT.php', {name: name}, function(data) {
            alert(data);
        });
    }
});

Avoid having duplicated IDs at all costs. That will save you from a lot of frustration later down the road.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I am getting only first row of my table

From Dev

Why Is My C# Code Only Displaying The First Row from my Database?

From Dev

My table is not getting created in Sqlite (Toast for dataNotInserted) ....Code snippet below

From Dev

Why is my script only accessing the first element in array?

From Dev

Why is my script only accessing the first element in array?

From Dev

Why my controller is not registered in below code?

From Dev

PHP/AJAX Why is my getAttribute only targeting the first line in the foreach code

From Dev

why setTimeout() only run my code once,at first time?

From Dev

Why is the compiler only compiling the first two sections of my code?

From Dev

The first row of my SQLite Database is not getting fetched and displayed in my RecyclerView

From Dev

Raw PHP code showing below my footer on my website

From Dev

Why am I getting a PHP Fatal error with my code?

From Dev

Why am I getting an Undifined Index error in my php code?

From Dev

My php Table code is not working

From Dev

My php Table code is not working

From Dev

My script works only for the first class

From Dev

Why my TableView first row is selected?

From Dev

My PHP row array is giving me duplicates in my table, and I don't know why

From Dev

why my TCP server code send a SYN/ACK on only first packet or only on the first connection?

From Dev

Why is my shell script cutting off the first number in my output?

From Dev

Why is my list function only outputting first value of my array?

From Dev

only the first line of my javascript code works

From Dev

Why my listview only detects the first checkbox?

From Dev

Why is only my first HTTP request running?

From Dev

Why is my for only working on the first variable?

From Dev

Why is my for loop only grabbing first element?

From Dev

Why the column in my database table is not getting created?

From Dev

getting error in my php/sql script?

From Dev

Why can't I "INSERT INTO" my table through my php script?

Related Related

  1. 1

    I am getting only first row of my table

  2. 2

    Why Is My C# Code Only Displaying The First Row from my Database?

  3. 3

    My table is not getting created in Sqlite (Toast for dataNotInserted) ....Code snippet below

  4. 4

    Why is my script only accessing the first element in array?

  5. 5

    Why is my script only accessing the first element in array?

  6. 6

    Why my controller is not registered in below code?

  7. 7

    PHP/AJAX Why is my getAttribute only targeting the first line in the foreach code

  8. 8

    why setTimeout() only run my code once,at first time?

  9. 9

    Why is the compiler only compiling the first two sections of my code?

  10. 10

    The first row of my SQLite Database is not getting fetched and displayed in my RecyclerView

  11. 11

    Raw PHP code showing below my footer on my website

  12. 12

    Why am I getting a PHP Fatal error with my code?

  13. 13

    Why am I getting an Undifined Index error in my php code?

  14. 14

    My php Table code is not working

  15. 15

    My php Table code is not working

  16. 16

    My script works only for the first class

  17. 17

    Why my TableView first row is selected?

  18. 18

    My PHP row array is giving me duplicates in my table, and I don't know why

  19. 19

    why my TCP server code send a SYN/ACK on only first packet or only on the first connection?

  20. 20

    Why is my shell script cutting off the first number in my output?

  21. 21

    Why is my list function only outputting first value of my array?

  22. 22

    only the first line of my javascript code works

  23. 23

    Why my listview only detects the first checkbox?

  24. 24

    Why is only my first HTTP request running?

  25. 25

    Why is my for only working on the first variable?

  26. 26

    Why is my for loop only grabbing first element?

  27. 27

    Why the column in my database table is not getting created?

  28. 28

    getting error in my php/sql script?

  29. 29

    Why can't I "INSERT INTO" my table through my php script?

HotTag

Archive