我是这个论坛的新成员。并使用 PHP 编码,所以作为新手,我希望得到你的所有帮助。
我面临的问题如下。
我有一个 MySQL 表“公告”,其中包含以下字段
id
----------
advert
----------
date
----------
file
----------
approv
----------
数据从页面填充到其中 - 除了批准之外,所有列都获得其值。要填充该字段,有一个新的 PHP 页面。字段 approv 根据其中复选框的勾号获取值“已批准”
我面临的问题是我无法读取显示 id 的文本框的值并获取相应的复选框值,以便特定记录获得批准并更新到 MySQL 表。
我写的代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Annpouncements | Pending List</title>
<style type="text/css">
.textinput {
height: 20px;
width: 20px;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
}
</style>
</head>
<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td height="164"><form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="11%" height="31" align="center"><label>Id</label></td>
<td width="15%" height="31" align="center"><label>Date</label></td>
<td width="52%" align="center"><label>Title</label></td>
<td width="22%" align="center"><label>Status</label></td>
</tr>
<?php
//Open the table announce from the database and list date in descending order
$result = mysql_query("SELECT * FROM announce ORDER by date DESC" )or
die(mysql_error());
//Define a variable to get the rows of the table
$ann = mysql_fetch_array($result);
//Define a variable to get the no of rows
$num = mysql_num_rows($result);
$i=0;
while($i<$num) {?>
<?php $approv[$i]= mysql_result($result,$i,"approv"); ?>
<tr>
<?php if($approv[$i] !== "approved"){?>
<td height="36" align="center"><input name="id" type="text"
class="textinput" id="id" value="<?php echo mysql_result($result,$i,"id");
?>" /></td>
<?php $ids = mysql_result($result,$i,"id");
//$inp = $_POST["id"][$i];
//echo 'Input value : ' .$inp. '<br/>' ?>
<td height="36" align="center"><label>
<?php echo mysql_result($result,$i,"date"); ?></label></td>
<td align="center"><label><?php echo mysql_result($result,$i,"advert");
?></label></td>
<td align="center"></label><input type="checkbox" name="approv[]" />
<label for="approv"></label></td>
<?php $idan = mysql_query("SELECT * FROM announce WHERE id == $ids"); ?>
<?php
if (isset($_POST['button']))
{
$apprv = $_POST["approv"];
//echo 'id = '.$ids.'<br/>';
$how_many = count($apprv);
//echo 'Row selected' .$how_many. '<br/>';
foreach ($_POST['approv'] as $apprValue)
$txtvalue[] = $_POST[$apprValue];
echo 'txtvalue = ' .$txtvalue. '<br/>';
mysql_query("UPDATE announce SET approv = 'approved'WHERE id ==
$idan ");
}
}
?>
<?php } ?>
</tr>
<?php
$i++;
}
?>
<tr>
<td height="44"> </td>
<td> </td>
<td align="center"> </td>
<td align="center"><input type="submit" name="button" id="button"
value="Submit" /></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
</tr>
</table>
因此,请帮助我获得正确的解决方案,以便仅针对已检查的那些行使用“已批准”值更新表。
期待您尽快提供宝贵的帮助