【发布时间】:2011-08-04 08:01:41
【问题描述】:
这里是前端设计师,不是 PHP 开发人员,我真的需要帮助。需要制作一个系统,允许客户端登录到他们自己的区域来更新表。该表将有大约 20 条记录,每行将使用单选按钮(4 个选项)进行编辑。只有 2 列,一列用于 ID,一列称为状态(可编辑数据)。
查看者只会看到客户端所做的更改以及根据状态更改该行的背景颜色,这意味着可编辑部分将必须保存 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(仅限客户端访问)否动态数据尚未更改,目前已硬编码 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>
【问题讨论】:
标签: php mysql html-table radio-button