比如说
<?php
$link = mysql_connect("localhost","root","123456");
mysql_query("use wiki");
$result = mysql_query("select * from user",$link);
echo "<form method=post>";
echo "<table border=1>\n";
echo "<tr>\n";
while ($field = mysql_fetch_field($result)) {
echo "<td>".$field->name."</td>\n";
}
echo "</tr>\n";
$num_rows = mysql_num_rows($result);
for ($i=0; $i < $num_rows; $i++){
list($id,$username,$password) = mysql_fetch_row($result);
echo "<tr>";
echo "<td name=id id=id>".$id."</td>";
echo "<td>".$username."</td>";
echo "<td>".$password."</td>";
echo "<td><a href=change.php>".修改."</a></td>";
echo "<td><a href=del.php>".删除."</a></td>";
echo "</tr>\n";
}
echo "</table>\n";
echo "</form>";
echo "<form action=add.php>\n";
echo "<input type=button value=".增加.">";
echo "</form>\n";
mysql_free_result($result);
mysql_close($link);
?>
在另外的php中,我该如何实时的获取$id?
取得ID后跳到A页面,同时把参数传进去。
就可以执行数据操作,取得一行数据。
...
echo "<td><a href=b.php?id=$id>".$username."</a></td>";
.....
在b.php里
$id=$_GET['id'];
就得到了
2个办法用session
3用cookies
4用表单传值