jeudi 22 février 2018

How can I put a form for each row of a table

Here's the thing, I need to update a selected row from a table, so I'm putting a form for each row of it (Every single row has an update button) and when I click update, it doesn't submit.

Here's my code, I'll be grateful with the solution.

<div class="table-responsive">
    <table class="table table-condensed">
        <thead class="">
            <tr>
                <th>ID</th>
                <th>Project</th>
                <th>Type</th>
                <th>Kick-Off Date</th>
                <th>Deadline Date</th>
                <th>Current Ninja</th>
                <th>Status</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <?php   
                $q = $_GET['q'];
                $sql="SELECT pr.project_name, pr.project_type, pr.project_start_date, pr.project_end_date, us.nombre, st.id_status, pr.id_project FROM NT_Projects as pr LEFT JOIN Project_Status as st on st.id_status = pr.id_status LEFT JOIN NT_Clients as cl on cl.id_client = pr.id_client LEFT JOIN usuarios as us on us.username = pr.username WHERE cl.id_client = $q";
                $result = mysql_query($sql) or die(mysql_error());
                $upt = 1;
                while($row = mysql_fetch_array($result)) {      
                    echo '
                    <div id="update-project">
                        <form method="post" action="sistema/_actions/updateProject.php" id="res-update-proj-'.$upt.'">';
                            $kickoff = date('m/d/Y', strtotime($row[2]));
                            $deadline = date('m/d/Y', strtotime($row[3]));
                            echo '<tr>';
                            echo '<td width="95px">
                                    <input class="form-control" name="id_Proj" type="text" value="'.$row[6].'" readonly>
                                  </td>';
                            echo "<td>" . $row[0] . "</td>";
                            echo "<td>" . $row[1] . "</td>";
                            echo "<td>" . $kickoff . "</td>";
                            echo "<td>" . $deadline . "</td>";
                            echo "<td>" . $row[4] . "</td>";
                            echo '<td width="225px">';
                            echo '<select class="form-control" name="proj_Status">';
                                $qStatus = "SELECT * FROM  Project_Status;";
                                $exStatus = mysql_query($qStatus);
                                while($rStatus = mysql_fetch_array($exStatus))
                                {
                                    if($row[5] == $rStatus[0])
                                        echo '<option value="'.$rStatus[0].'" selected>'.$rStatus[1].'</option>';
                                    else
                                        echo '<option value="'.$rStatus[0].'">'.$rStatus[1].'</option>';
                                }
                            echo '</select>
                                </td>
                                <td class="text-center">
                                    <button type="submit" class="btn btn-sm btn-primary btn-UProj" value="res-update-proj-'.$upt.'">Update</button>
                                    <div id="res-update-proj-'.$upt.'" style="width: 100%; margin:0px; padding:0px;"></div>
                                </td>
                            </tr>
                        </form>
                    </div>';
                $upt = $upt + 1;
                }
            ?>
        </tbody>    
    </table>
</div>

That code is being called from another HTML with ajax




Aucun commentaire:

Enregistrer un commentaire