现在做个文具采购的小练习,通过ID可以查询自己的文具订购情况,并可以进行数量的修改,代码如下:
info.php:
<?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里?或者修改数量有什么更好的写法?谢谢各位大大

解决方案 »

  1.   

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

  2.   

    不好意思,比较笨没听懂,貌似我表建的也有问题,求教诲user表:
    userId(主键)   userName 
    1000   allen
    1001   jackstationery表:
    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
      

  3.   

    是不是应该再建个表,单独列出所有文具的属性:
    items表:
    items_id(主键)    items
    1                 黑色水笔
    2                 蓝色水笔
    3                 红色水笔
    4                 黑色水笔芯
    5                 蓝色水笔芯然后怎么做呢?
      

  4.   

    是的。 stationery表中存items_id不是更好。
    建议三个表的主键直接用id,听起来更好。