English 中文(简体)
浏览
原标题:Edit a table by row

我有一个表格,其中载有从一个表中检索的数据。 我在每一行的末尾都附有一个ed子。 ed子允许用户编辑某一项目的信息。 我希望ed子能够让用户了解所附信息。 例如:

--------------------------
NAME | AGE | GENDER |
--------------------------
  A  |  4  | Female |EDIT
--------------------------
  B  |  9  | Female |EDIT
--------------------------
  C  |  2  |  Male  |EDIT
--------------------------

If I click the EDIT button on A s row, it would allow me to edit A s information. Please help.

<form id="edit" name="edit" method="post" action="edititem.php">
    <table width="792" border= 1  align= center  cellpadding= 0  cellspacing= 0  id= usertable >
    <tr bgcolor=#706C4B  style= color:black >
        <td width="16%" align= center   id="box_header2" style= width:10% >Item Name</td>
        <td width="16%" align= center   id="box_header2" style= width:10% >Item Quantity</td>
        <td width="14%" align= center  id="box_header2" style= width:13% >Storage Capacity</td>
        <td width="13%" align= center  id="box_header2" style= width:11% >Brand</td>
        <td width="13%" align= center  id="box_header2" style= width:11% >Color</td>
        <td width="13%" align= center  id="box_header2" style= width:12% >MAC Address</td>
        <td width="13%" align= center  id="box_header2" style= width:12% >S/N Number</td>
        <td width="13%" align= center  id="box_header2" style= width:12% ></td>
    </tr>

 <?php
 $sql="select * from item";
 $result=mysql_query($sql);
  while ($row=mysql_fetch_array($result))
    {
    ?>
    <tr bgcolor=#cfccb7 style= color:black >  
        <td><div align="center"><?php echo $row[ item_name ]?></div></td>
        <td><div align="center"><?php echo $row[ item_quantity ]?></div></td>
        <td><div align="center"><?php echo $row[ item_capacity ]?></div></td>
        <td><div align="center"><?php echo $row[ item_brand ]?></div></td>
        <td><div align="center"><?php echo $row[ item_color ]?></div></td>
        <td><div align="center"><?php echo $row[ item_mac ]?></div></td>
        <td><div align="center"><?php echo $row[ item_sn ]?></div></td>
        <td><div align="center"><input type="submit" name="button" id="button" value="Edit" /></div></td>
    </tr>
     <?php
     }
     ?>


    </table>
    </form>
问题回答

This is a partial answer that may get you started. When the user clicks the button, you need to execute a SQL statement something like this:

//define the update query
$SQLQuery = " update YourTableName
set column1 = ".$phpVariable1." ,
column2 = ".$phpVariable2."
where keyCol = ".$phpVariableKey." ";

// run the update query
$result = mysql_query($SQLQuery);

$phpVariableKey contains, in your case, the value A .

从理论上讲,你希望给每个浏览点一个独特的价值,即数据库中的这一增长(即:纽伦-1,纽顿-2等)。 然后,你可以接受并处理根据纽特州价值提供的形式投入。 例如,你可以显示基于纽特市值的编辑屏幕,或显示可编辑的文本领域,而不是表格中该行的内容。

或者,你可以通过贾瓦文向纽州附上一个点击手器,将桌子内容替换成一个特定行的校正文本input。 在处理名册表格时,你可以根据这些新文本领域的价值观更新数据库。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签