这里的前端设计师不是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>