从前端编辑多列中的数据

时间:2017-03-29 05:25:04

标签: php mysql

我在数据库中有一个表,我可以一次编辑特定行的列。但是,我想一次编辑单行的多个列,并选择编辑,然后将其保存到数据库,我们可以通过在数据库本身进行编辑从后端进行。但是,我想从前端做到。现在我能够在表格中显示数据。我是编码的新手,所以任何人都可以帮助我在哪里开始同时编辑多个列的特定任务。 这是显示数据的代码..

<?php
include('db.php');
include 'header.php';
include 'gobacktomenu.php';
$TND_ID =  $_GET['TND_ID'];
$sql = "SELECT * FROM new_tnds WHERE TND_ID = ('".$TND_ID."')"; 
$result = $link->query($sql);
echo "<div style='overflow-x:auto;'><table border = '1'><font size = '2' face='verdana'>
<th>TND ID</th><th>Site name S1</th><th>Site name S2</th><th>Call sign S1</th><th>Idea ID S1</th><th>Call sign S2</th><th>Idea ID S2</th><th>Site to integrate</th><th>True azimuth (°) S1</th><th>True azimuth (°) S2</th><th>Pathlength (km)</th><th>TR Antenna diameter (m)</th><th>TR Antenna height (m) S1</th><th>TR Antenna height (m) S2</th><th>Channel ID S1</th><th>Channel ID S2</th><th>Design frequency S1</th><th>Design frequency S2</th><th>Polarization</th><th>Radio model</th><th>TX power (dBm)</th><th>Receive signal (dBm)</th><th>Planning Remarks</th><th>Projects Remarks Uploaded by</th><th>O & M Remarks Uploaded by</th><th>Planning Remarks Uploaded by</th><th>TXN NOC Remarks Uploaded by</th></tr>";

if ($result->num_rows > 0) {
    // output data of each row
    $row = $result->fetch_assoc();

        echo "<tr><td>".$row["TND_ID"]."</td><td>".$row["Site_name_S1"]."</td><td>".$row["Site_name_S2"]."</td><td>".$row["Call_sign_S1"]."</td><td>".$row["Idea_ID_S1"]."</td><td>".$row["Call_sign_S2"]."</td><td>".$row["Idea_ID_S2"]."</td><td>".$row["Site_to_integrate"]."</td><td>".$row["True_azimuth_S1"]."</td><td>".$row["True_azimuth_S2"]."</td><td>".$row["Path_length_(km)"]."</td><td>".$row["TR_Antenna_diameter_(m)_S1"]."</td><td>".$row["TR_Antenna_height_(m)_S1"]."</td><td>".$row["TR_Antenna_height_(m)_S2"]."</td><td>".$row["#1_Channel_ID_S1"]."</td><td>".$row["#1_Channel_ID_S2"]."</td><td>".$row["#1_Design_frequency_S1"]."</td><td>".$row["#1_Design_frequency_S2"]."</td><td>".$row["Polarization"]."</td><td>".$row["Radio_model_S1"]."</td><td>".$row["TX_power_(dBm)_S1"]."</td><td>".$row["Receive_signal_(dBm)_S1"]."</td><td>".$row["Planning_Remarks"]."</td><td>".$row["Projects_remarksupdated_user_name"]."</td><td>".$row["O_M_remarksupdated_user_name"]."</td><td>".$row["Planning_remarksupdated_user_name"]."</td><td>".$row["txn_noc_remarksupdated_user_name"]."</td></tr>";

}
echo "</table></div>";
$link->close();
?>

3 个答案:

答案 0 :(得分:0)

你可以使用这个结构,这可以用来编辑2个表和多个列表a有列(辅助,a1,a2)表b有列(bid,b1,b2)我知道代码看起来很粗糙但只是在5分钟内写下来给你一个想法

<?php
//this only executes when button is clicked
if (isset($_POST["submit"] && $_POST["submit"]!=""){
    $counta=$_POST["aid"];
    //loops through the posts inside here do your query with the set command
    //like "update a set a1='$a1',a2='$a2" where aid ='$_POST["aid'][$i]"

    for($i=0;$i<$count;$i++){
        $a1[$i]=$_POST["a1"][$i];
        $a2[$i]=$_POST["a2"][$i];
        //your query here
        }
    $countb=$_POST["bid"];
    //loops through the posts inside here do your query with the set command
    //like "update b set b1='$b1',b2='$b2" where aid ='$_POST["bid'][$i]"
    for($i=0;$i<$count;$i++){
        $a1[$i]=$_POST["a1"][$i];
        $a2[$i]=$_POST["a2"][$i];
        }
//now the part before the button gets clicked
//do your query to select data from database
?>

<html>
<body>
//creating loop inside html

<?php
$a=0;
while($rowa = mysql_fetch_assoc($resulta){
?>

//getting the input data
<input type="checkbox" name="aid[]" value="<?php echo $row["aid"]; ?>>
<label>a1</label>
<input type="text" name="a1[]" value="<?php echo $row["a1"]; ?>>
<label>a2</label>
<input type="text" name="a2[]" value="<?php echo $row["a2"]; ?>>
//ending the loop

<?php
$a++;
}
//b works the same as a
$b=0;
while($rowb = mysql_fetch_assoc($resultb){
?>

<input type="checkbox" name="bid[]" value="<?php echo $row["bid"]; ?>>
<label>b1</label>
<input type="text" name="b1[]" value="<?php echo $row["b1"]; ?>>
<label>b2</label>
<input type="text" name="b2[]" value="<?php echo $row["b2"]; ?>>

<?php
$b++;
}
?>

<input type="submit" name="submit" value="submit">
</body>
</html>

答案 1 :(得分:0)

编辑时需要使用表单而不是表格,并在表单输入上传递获取的值,并在表单提交时写入更新查询。

if ($result->num_rows > 0) {
// output data of each row
$row = $result->fetch_assoc();
}
if(isset($_POST['submit']))
{
$query = "update details set Site_name_S1='$_POST['submit']',Site_name_S2='$_POST['Site_name_S2']',Call_sign_S1='$_POST['Call_sign_S1']',Idea_ID_S1='$_POST['Idea_ID_S1'] where TND_ID=$_POST['TND_ID']";

$res = mysql_query($query);
}
<form method="post">
<input type="text" name="id" value="<?php echo $row['TND_ID'] ;?>" >
<input type="text" name="Site_name_S1" value="<?php echo $row['Site_name_S1'] ;?>" >
<input type="text" name="Site_name_S2" value="<?php echo $row['Site_name_S2'] ;?>" >
<input type="text" name="Call_sign_S1" value="<?php echo $row['Call_sign_S1'] ;?>" >
<input type="text" name="Idea_ID_S1" value="<?php echo $row['Idea_ID_S1'] ;?>" >
<input type="submit" name="submit">
</form>

在编写更新查询时只需检查引号。

答案 2 :(得分:0)

您可以使用Ajax 只是一段代码: .............

(Get)TransactionType

.............

比小Ajax

     <td><input type="text" row_id=".$some_row_num_from_table." 
col-name=".$some_col_name_from_table." disabled class="some-val" value=".$some_from_base."></td>