前台:网页,后台:MySQL数据库表;程序思想:选择id2=1的纪录进行修改,三个按钮;B0:删除 B1:保留 B2:更新。错误地方:1. 假定从第i条记录开始修改,那么第i条记录会被正确显示(前台)/修改(后台),2. 刷新网页后,前台:网页仍然显示第i条记录,而后台:MySQL数据库表实际上已经指向第i+1条记录,如有更新,仍然是第i+1—条记录被更新;3. 延续2的错误,刷新网页后,前台:网页显示第K条记录,而后台:MySQL数据库表实际上已经指向第K+1条记录,如有更新,仍然是第K+1条记录被更新;....<?php//Connect to database$connect = mysql_connect("andy","kiong","Password")or
die("Could not connect : " . mysql_error()); ;
mysql_select_db("kiong_userinfo",$connect)or die("Could not
connect : " . mysql_error());// select a record$result = mysql_query("SELECT * FROM putonServer where id2=1",
$connect);
$newline = "
";
$row = mysql_fetch_array($result) or die(mysql_error());
$this_id=mysql_result($result,0,"id");
$this_body=mysql_result($result,0,"body");//show the content of the recordecho $this_id;
echo $newline;
echo $this_body;
?><HTML>.
<!--Show the webpage, where the content(body field of putonServer) in
the record will be shown,
Three button: Discard(B0),Agree(B1) and Update(B0) will be shown as
well -->
.....<HTML><?php//Make a deleted for the record which should be deleted from the
databasefunction DelMySQL($this_id,$connect)
{
$next_id=$this_id+1;
$query_B0="update putonServer SET id2=7 where id='$this_id'";
$query_B0_2="update putonServer SET id2=1 where
id='$next_id'";
$result_B0=mysql_query($query_B0,$connect);
if (!$result_B0) {
die ('Puke, Wrong2 ' . mysql_error());
}
$result_B0_2=mysql_query($query_B0_2,$connect);
if (!$result_B0_2) {
die ('Puke, Wrong ' . mysql_error());
}
}//Make an agree for the record which should be kept no change in
the databasefunction AgrMySQL($this_id,$connect)
{
$next_id=$this_id+1;
$query_B0="update putonServer SET id2=7 where id='$this_id'";
$query_B0_2="update putonServer SET id2=1 where
id='$next_id'";
$result_B0=mysql_query($query_B0,$connect);
if (!$result_B0) {
die ('Puke, Wrong2 ' . mysql_error());
}
$result_B0_2=mysql_query($query_B0_2,$connect);
if (!$result_B0_2) {
die ('Puke, Wrong ' . mysql_error());
}
echo "Processoooo".$newline;
echo $this_id;
}//modify the selected row in a database
function UpdMySQL($this_id,$connect,$cate,$orie)
{
$next_id=$this_id+1;
$query_B2 ="UPDATE putonServer SET
category='$cate',orientation='$orie' where id='$this_id'";
echo $this_id.$newline;
$result_B2=mysql_query($query_B2,$connect);
if (!$result_B2) {
die ('Puke, Wrong2 ' . mysql_error());
}
$query_B2_1="update putonServer SET id2=4 where
id='$this_id'";
echo $this_id.$newline;
$query_B2_2="update putonServer SET id2=1 where
id='$next_id'";
echo $this_id.$newline;
$result_B2_2=mysql_query($query_B2_2,$connect);
if (!$result_B2_2) {
die ('Puke, Wrong ' . mysql_error());
}
$result_B2_1=mysql_query($query_B2_1,$connect);
if (!$result_B2_1) {
die ('Puke, Wrong2 ' . mysql_error());
}
}// When different button is clicked, do different action on the
databaseif($_POST[B0]){
DelMySQL($this_id,$connect);
}
if($_POST[B1]){
AgrMySQL($this_id,$connect);
}
if($_POST[B2]){
UpdMySQL($this_id,$connect,$_POST[R2],$_POST[sliderinput22]);
}
?><Description for the database>
+-------------+------------------+------+-----+---------
+----------------+
| Field | Type | Null | Key | Default |
Extra |
+-------------+------------------+------+-----+---------
+----------------+
| id | int(11) | | PRI | NULL |
auto_increment |
| id2 | int(11) | | | 0
| |
| users | int(10) unsigned | | | 0
| |
| date | text | YES | | NULL
| |
| time | text | YES | | NULL
| |
| docuname | text | YES | | NULL
| |
| body | text | YES | | NULL
| |
| orientation | int(11) | | | 0
| |
| category | int(11) | | | 0
| |
+-------------+------------------+------+-----+---------
+----------------+
die("Could not connect : " . mysql_error()); ;
mysql_select_db("kiong_userinfo",$connect)or die("Could not
connect : " . mysql_error());// select a record$result = mysql_query("SELECT * FROM putonServer where id2=1",
$connect);
$newline = "
";
$row = mysql_fetch_array($result) or die(mysql_error());
$this_id=mysql_result($result,0,"id");
$this_body=mysql_result($result,0,"body");//show the content of the recordecho $this_id;
echo $newline;
echo $this_body;
?><HTML>.
<!--Show the webpage, where the content(body field of putonServer) in
the record will be shown,
Three button: Discard(B0),Agree(B1) and Update(B0) will be shown as
well -->
.....<HTML>
<?php
// When different button is clicked, do different action on the
databaseif($_POST[B0]){
DelMySQL($this_id,$connect);
}
if($_POST[B1]){
AgrMySQL($this_id,$connect);
}
if($_POST[B2]){
UpdMySQL($this_id,$connect,$_POST[R2],$_POST[sliderinput22]);
}
//modify the selected row in a database
function UpdMySQL($this_id,$connect,$cate,$orie)
{
$next_id=$this_id+1;
$query_B2 ="UPDATE putonServer SET
category='$cate',orientation='$orie' where id='$this_id'";
echo $this_id.$newline;
$result_B2=mysql_query($query_B2,$connect);
if (!$result_B2) {
die ('Puke, Wrong2 ' . mysql_error());
}
$query_B2_1="update putonServer SET id2=4 where
id='$this_id'";
echo $this_id.$newline;
$query_B2_2="update putonServer SET id2=1 where
id='$next_id'";
echo $this_id.$newline;
$result_B2_2=mysql_query($query_B2_2,$connect);
if (!$result_B2_2) {
die ('Puke, Wrong ' . mysql_error());
}
$result_B2_1=mysql_query($query_B2_1,$connect);
if (!$result_B2_1) {
die ('Puke, Wrong2 ' . mysql_error());
}
}
?>
你的$this_id一直没变,当然$next_id也就一直没变啦.
function里面的加一个全局的变量,先判断有没有付过值,有的话,就+1,没有的话,就用function的实参$this_id.不知道这是不是你想要的...
我实在是找不出问题在那里,三周了。
这种算法没什么不可靠的吧?
我自己写的,用文本作记录的话,问题依旧。
所以应该是php本身结构有问题。你有什么原码可供参考么?谢谢。
比如a.php?id=10改成a.php?id=10&t=1,//这个t不需要用。只是告诉浏览器不要用缓存。
试试吧,解决了别忘了结贴。
为什么要加1,还有我感觉你这个方法有点晕啊
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
<META HTTP-EQUIV="expires" CONTENT="0">