0

I have a table employee in database. I was able to add, fetch and display each row in that table in an html table dynamically using php.

<a href='add-employee.php' style='float:right;'>Add Employee</a>

<table class="table table-responsive">

     <thead>
           <th><strong>Employee Id</strong></th>
           <th><strong>Last Name</strong></th>
           <th><strong>First Name</strong></th>
           <th><strong>Department</strong></th>
           <th><strong>Position</strong></th>
           <th><strong>Telephone</strong></th>

     </thead>

     <tbody>   
        <?php

           $load_employees = mysql_query("SELECT * FROM tbl_employee");
           $loaded_employees = mysql_num_rows($load_employees);

              while($y=mysql_fetch_array($load_employees)){
                    $emp_id = $y['emp_id'];
                    $last = $y['emp_lname'];
                    $first = $y['emp_fname'];
                    $department = $y['emp_department'];
                    $position = $y['emp_pos'];
                    $tel = $y['emp_tel'];

                    echo "<tr>
                            <td>$emp_id</td>
                            <td>$last</td>
                            <td>$first</td>
                            <td>$department</td>
                            <td>$position</td>
                            <td>$tel</td>
                          </tr>";
                }
          ?>                              
      </tbody

My problem is that wasn't able to update a specified row in the html table. What I would like to happen is let's say for example there is already 5 entries in that table which means 5 rows, when a user clicks on a certain row , it would pass the emp_id which is the primary key for each row and redirect to update-emp.php page which contains a form for updating the row.

Pretorian
  • 41
  • 1
  • 3
  • 2
    You could create a hyperlink, ie. `Edit`, and then use `$_GET['emp_id']` in `update-emp.php`. **OR** You could build a form for each row, to post the `emp_id` so then you could use `$_POST['emp_id']`, ie. `
    `
    – Sean Jan 16 '16 at 03:43
  • Another option is attaching a javascript onclick event to the row, with the same url as Sean suggests. I'd go with the hyperlink, personally. – rjdown Jan 16 '16 at 03:46
  • Why are you using database functions that haven't been supported for 5 years, and aren't even present in the current version of PHP? http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – miken32 Jan 16 '16 at 03:49
  • ok i'll try it thanks – Pretorian Jan 16 '16 at 03:53

0 Answers0