+ -
当前位置:首页 → 问答吧 → 新手上路,如何获取动态变量?

新手上路,如何获取动态变量?

时间:2011-08-29

来源:互联网

现在做个文具采购的小练习,通过ID可以查询自己的文具订购情况,并可以进行数量的修改,代码如下:
info.php:
PHP code
<?php
$conn = mysql_connect("localhost","root","") or die("不能连接到服务器!".mysql_error());
$db_selected = mysql_select_db("test",$conn) or die("不能连接到服务器!".mysql_error());
mysql_query("set names gb2312");        //选择编码格式GB2312
$info = $_POST["userId"];                //获取查询内容
$sql = mysql_query("select user.userName,stationery.items,stationery.quantity from user,stationery where stationery.userId AND user.userId='$info'");
$row = mysql_fetch_object($sql);        //获取查询结果集
if(!$row){
    echo "<font color='red'>您搜索的信息不存在!</font>";
}
?>
<div>欢迎您,<?php echo $row->userName;?></div>
<?php
    do{            //$user_id= $row["user.userName"];
?>
<table border="1">
<tr>
<td align="center" width="100"><?php echo $row->userName;?></td>
<td align="center" width="300"><?php echo $row->items;?></td>
<td align="center" width="30"><input type="text" name="quan[<?php *** ?>]" value="<?php echo $row->quantity;?>" /></td> 
</tr>
</table>
<?php
}while($row = mysql_fetch_object($sql));
mysql_free_result($sql);
?>
<input type="button" value="确认" onclick="window.location='index.php'">
<input type="button" value="修改" onclick="window.location='order.php'">
</html>


请问表中的name="quan[<?php *** ?>]"怎么写?才能够动态的获取到每个文具的数量信息,使得我可以进入修改页面把各个变量的值update到mysql里?或者修改数量有什么更好的写法?谢谢各位大大

作者: hi_allen_liu   发布时间: 2011-08-29

前面的sql语句,将stationery 表的主键信息也搜索出来,即可

作者: amani11   发布时间: 2011-08-29

不好意思,比较笨没听懂,貌似我表建的也有问题,求教诲

user表:
userId(主键) userName 
1000 allen
1001 jack

stationery表:
orderId(主键) items quantity userId
1 Pen(Black) 黑色水笔 GP-009 0 1000
2 Pen(Blue) 蓝色水笔 GP-009 0 1000
3 Pen(Red) 红色水笔 GP-009 0 1000
4 Pen Refill(Black) 黑色水笔芯 919 0 1000
5 Pen Refill(Blue) 蓝色水笔芯 919 0 1000



作者: hi_allen_liu   发布时间: 2011-08-29

热门下载

更多