mysql - Edit database row from php page -
i have 2 php pages. - first 1 has form insert data in database. - second diplays data of database.
how i, conceptually, adding each row button "update", allow me change of value of row (in exemple value of 2 dropdownlist) , update info in database well.
this code able looking in internet , have 2 problems: first, working second update button (so second row updated). second, changes not reflected dropdowlist. (means if change second row value database updated not dropdownlist).
note implemented 2 columns
<td>" . $row['status'] . "</td> <td>" . $row['priority'] . "</td> only check value in database changes.
    <form method="post" action="job-status.php">            <?php      include("../includes/connection.php");          if($link->connect_errno > 0){             die('unable connect database [' . $link->connect_error . ']');         }          if(isset($_post['update'])) {            $results = $link->query("update job set status='$_post[status]',          priority='$_post[priority]' id='$_post[hidden]'");          }                $sql = "select * job";         if(!$result = $link->query($sql)){             die('there error running query [' . $link->error . ']');         }         echo "     <table class='table'>         <thead>             <tr>";         /* field information columns */         while ($finfo = $result->fetch_field()) {             echo "             <th>" . $finfo->name . "</th>";         }         echo "             </tr>         </thead>         <tbody>";         while($row = $result->fetch_assoc()){        echo "<tr class='info'>                      <td>" . $row['id'] . "</td>                      <td>" . $row['device'] . "</td>                     <td>" . $row['model'] . "</td>                      <td>" . $row['problem'] . "</td>                     <td><select class='form-control col-sm-10' id='status' name='status'>                          <option value='new'>new</option>                          <option value='progress'>progress</option>                          <option  value='wait'>wait</option>                          <option value='done'>done</option>                          <option value='close'>close</option>                    </select></td>                      <td><select class='form-control col-sm-10' id='priority' name='priority'>                      <option value='high'>high</option>                          <option value='medium'>medium</option>                      <option  value='low'>low</option>                      </select></td>                         <td>" . $row['status'] . "</td>                        <td>" . $row['priority'] . "</td>                     <input type=hidden name=hidden value=" . $row['id'] . ">  <td><button type='submit' class='btn btn-primary btn-sm' name='update'>update</button></td>  <td> <a class='btn btn-primary btn-sm'  data-toggle='modal' data-target='#mymodal'>info</a></td>                 </tr>";          }          echo "         </tbody>   </table>";  ?>    </form> 
you can use td each row of table:
"<td>" . $row['name'] . '</td><td><a href="link">edit</a>' . "</td>" the link link controller, in case sing mvc pattern, , can pass id of que row want delete. mean somethig like:
"<td>" . $row['name'] . "</td><td><a href='clientes/editar?id=" . $row['id'] . "'>edit</a> . "</td>" this way can edit row clicking "edit" link. remember implement in controller logic updating row specific id. purpose can use orm wich can database access.

Comments
Post a Comment