2016-10-01 40 views
-1

這是表格形式,我將選擇該行通過按鈕編輯如何從表格行獲取值?

$query = "SELECT * FROM tbl_document LIMIT $start, $end"; 
$result = mysqli_query($con,$query); 
echo "<table border='1' width='300' height='160' align = center id='result'>"; 
echo '<tr> 
    <th width="80">ID</th> 
    <th width="200">Title</th> 
    <th width="260">Presented To</th> 
    <th width="260">Presented By</th> 
    <th width="160">Date Submitted</th> 
    <th>Location</th> 
    <th width="17%">Option</th> 
</tr>'; 
while($row = mysqli_fetch_array($result)){ 
    echo "<tr align = center >"; 
    echo "<td width='20' height='60'>" .$row['ID']. "</td>"; 
    echo "<td width='120' height='60'>" .$row['Title']. "</td>"; 
    echo "<td>" .$row['Presented_To']. "</td>"; 
    echo "<td>" .$row['Presented_By']. "</td>"; 
    echo "<td>" .$row['Date_Submitted']. "</td>"; 
    echo "<td>" .$row['Location']. "</td>"; 
    echo "<td width='17%'>"; 
?> 
<p> 
    <button onclick="document.getElementById('edtID').style.display='block'" value="<?php echo $row['ID']; ?>" class="w3-btn w3-blue w3-border-large w3-circle" id="edit" name="edit" style="width:60%"><i class="fa fa-edit"></i>&nbsp;Edit</button> 

這是第二次代碼這種形式是有模式的,我按一下桌上的按鈕,模式顯示,您可以編輯編輯但我的代碼缺少什麼?

<form method="post" action="<?php $_SERVER['PHP_SELF'];?>"> 
<p> 
<label class="w3-label w3-text-black"><strong>Title:</strong></label> 
<input class="w3-input w3-hover-light-blue w3-animate-input w3-border-large w3-light-grey" style="width:100%" type="text" id="title" name="title" placeholder="Title" value=<?php $row['Title']; ?>required></span> 
</p> 
</form> 
+0

來自表格行的值 – RiggsFolly

回答

0

關於你的第二形式(您模式),我看不出有什麼迴音,以顯示你的冠軍的價值

<form method="post" action="<?php $_SERVER['PHP_SELF'];?>"> 
<p> 
<label class="w3-label w3-text-black"><strong>Title:</strong></label> 
<input class="w3-input w3-hover-light-blue w3-animate-input w3-border-large w3-light-grey" style="width:100%" type="text" id="title" name="title" placeholder="Title" value=<?php echo $row['Title']; ?>required></span> 
</p> 
</form> 

而且,你的第一個形式,你可以這樣寫

<table border='1' width='300' height='160' align=center id='result'> 
    <tr> 
    <th width="80">ID</th> 
     <th width="200">Title</th> 
     ... 
    </tr> 

    <?php 

    while($row = mysqli_fetch_array($result)) 
    { 
     echo "<tr align = center >"; 
     echo "<td width='20' height='60'>" .$row['ID']. "</td>"; 
     echo "<td width='120' height='60'>" .$row['Title']. "</td>"; 
     ... 
    ?> 

    <p> 
     <button onclick="document.getElementById('edtID').style.display='block'" value="<?php echo $row['ID']; ?>" class="w3-btn w3-blue w3-border-large w3-circle" id="edit" name="edit" style="width:60%"> 
     <i class="fa fa-edit"></i>&nbsp;Edit 
     </button> 
    </p> 

    <?php 

    } 

    ?> 

最後,您應該開始使用PDO處理與數據庫相關的所有事情。