简体   繁体   中英

about editing only 1 row in a table

How to edit a row in mysql using php. I have a table , i will fetch it into php page to display the table in html format and at the end i have a edit button when i click edit button then the row should be editable and i can enter new values and that should update in the same table row.. after c licking edit button the button should change to submit/update...

这是表的图像,此处的值在文本框中,但在用户单击第一次编辑时为只读,第一行应可写,输入的值应存储

you can use this simple method:

HTML for each EDIT link add the id of the row:

<a href="edit.php?id=4">EDIT</a>

edit.php :

if(isset($_GET["id"])){
   echo "start editing the row that have id".$id;
}

This is one of the basic actions, which falls into the category of CRUD functions. Here are the few steps you need to know to get you started.

  • Pass a unique id of the record a edit page or class.
  • You may attach the id , to the edit link of each page.
  • This page will use this id and fetch the record from the database
  • The details will be used to fill up of a form, from which the user will update the records.
  • The form will also keep the record of the id in most probably a hidden element.
  • Next, when this edit form is submitted, a processing will create a UPDATE query based on the data and execute them.

The Jquery Editable Data Tables plugin could be the best solution you need. See code google for documentation and implementation here: http://code.google.com/p/jquery-datatables-editable/

Note: Doing basic CRUP is completely time-consuming, both in the back-end and front-end, and other people usually solved this predicament a long time ago, you just need to HUG their solutions, and customize them to your liking.

But always when you asked help of other tell what you have tried..

This is just rough graph:-

$data = $_REQUEST;

if((isset($data['user_ids'])) && (count($data['user_ids']) == 1)){

 $id =$data['user_ids'][0];
    $sql= "UPDATE no_service SET `Status` = '$data[status_select_update]' WHERE id = $id ";

}elseif ((isset($data['user_ids'])) && (count($data['user_ids']) > 1)) {

    $ids = implode(",",$data['user_ids']);
    $sql= "UPDATE no_service SET `Status` = '$data[status_select_update]' WHERE id IN($ids)";

}else{
}

Edit is totally based on your id.. what you are passing.. Based on that id it will updated your records in Mysql..

I hope it will help..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM