這裏的前端設計師不是PHP開發人員,我真的需要幫助。需要建立一個系統,允許客戶登錄到自己的區域來更新表格。該表格將包含約20條記錄,每行將用單選按鈕編輯(4個選項)。只有2列,一個用於ID,另一個稱爲狀態(可編輯數據)。使用單選按鈕更新數據庫的簡單PHP任務
查看器將只能看到客戶端所做的更改以及根據狀態對該行進行的背景顏色更改,這意味着可編輯部分必須保存2個數據(整數值才能更改顏色和名稱的狀態,例如單選按鈕改變顏色的值,以及用於將文本回顯到單元中的按鈕的標籤)。將處理大約登錄系統後...
數據庫設置:
Database: test
Table: fire_alert
Structure:
id (INT, PRIMARY); color(INT); warning(VACHAR);
connect.php
:
<?php
// Database Variables (edit with your own server information)
$server = 'localhost';
$user = 'root';
$pass = 'root';
$db = 'test';
// Connect to Database
$connection = mysql_connect($server, $user, $pass)
or die("Could not connect to server ... \n" . mysql_error());
mysql_select_db($db)
or die("Could not connect to database ... \n" . mysql_error());
?>
view.php
:
<div id="container">
<?php
// connect to the database
include('connect.php');
include("header.php");
// get results from database
$result = mysql_query("SELECT * FROM fire_alert")
or die(mysql_error());
echo "Current date - " . date("Y/m/d") . "<br /><br />";
// display data in table
echo "<table>";
echo "<tr> <th>Area</th> <th>Status</th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array($result)) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['warning'] . '</td>';
echo "</tr>";
}
// close table>
echo "</table>";
echo '<td><a href="edit.php' . $row['id'] . '">Change Area Status</a></td>';
?>
</div>
<body>
</body>
</html>
edit.php
(客戶端訪問僅)沒有動態da TA改變的是,硬編碼的HTML至今:
<?php include("header.php"); ?>
<?php include("connect.php"); ?>
<div id="container" class="edit">
<div id="radio1">
<?
$result = mysql_query("SELECT * FROM fire_alert")
or die(mysql_error());
echo "Current date - " . date("Y/m/d") . "<br /><br />";
?>
<table class="edit">
<tr><th>Area</th><th>Status</th></tr>
<tr>
<td>1</td>
<td>
<form method="post" action="edit.php">
<input type="radio" id="radio1" name="radio" value="1" /><label for="radio1">Safe</label>
<input type="radio" id="radio2" name="radio" value="2" /><label for="radio2">Caution L1</label>
<input type="radio" id="radio3" name="radio" value="3" /><label for="radio3">Caution L2</label>
<input type="radio" id="radio4" name="radio" value="4" /><label for="radio4">Closed</label>
</form>
</td>
</tr>
</table>
</div>
<?php echo '<td><a href="view.php' . $row['id'] . '">Update</a></td>'; ?>
</div>