在一个数据库的item表中查询owner字段的值为mmxx的记录,会出现很多记录,他们的ID是自动编号,只有owner字段的值是相同的。现在要在查询出来的记录中任意选择一条,并对该条信息进行更新,同时返回该条记录的ID值。
比如: id owner
2 mmxx
3 mmxx
4 mmxx
... mmxx
10 mmxx
比如: id owner
2 mmxx
3 mmxx
4 mmxx
... mmxx
10 mmxx
select id from item where owner='mmxx' order by rand() limit 0,1
这条语句可以将owner为mmxx的记录随机排序,并取出第一条
然后用这个id来更新记录既可
第一步:取出owner=id的所有记录,随机取一条
$sql="select * from tablename where order owner='mmxx' by rand() limit 1"
$result=mysql_query($sql);if($rows=mysql_fecth_array($result){
$id=$ows['id'];
}
取出id第二步:如果有记录则$sql="update tablename set 字段='字段值',字段='字段值' where id='id值' "
ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order owner='bdmxd' by rand() limit 0,1' at line 1..
mysql> select * from inventoryitems where order owner='bdmxd' by rand() limit 1;
ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order owner='bdmxd' by rand() limit 1' at line 1;
大哥啊,怎么语法有错误啊?我用的是mysql5.0。希望指点下啊
$result=mysql_query($sql); if($rows=mysql_fecth_array($result){
$id=$rows['inventoryitemid'];
}
$inventoryeitemsa = mysql_query("update inventoryitems set `characterid` = ".$name["id"]." and `itemid`=".$item["itemid"]." and `inventorytype`='1' and `position`=".$j." and `quantity`='1' and `owner`=".$name["name"]." where 'inventoryitemid`='$id' ",$connsql); $inventoryequipment = mysql_query("update inventoryequipment set `inventoryitemid` = '$id' and `upgradeslots` = ".$item["upgradeslots"]." and `level` = ".$item["level"]." and `str` = ".$item["str"]."' and `dex`=".$item["dex"]." and `int`=".$item["int"]." and `luk`=".$item["luk"]." and `hp`=".$item["hp"]." and `mp`=".$item["mp"]." and `watk`=".$item["watk"]." and `matk`=".$item["matk"]." and `wdef` = ".$item["wdef"]." and `mdef`=".$item["mdef"]." and `acc`=".$item["acc"]." and `avoid`=".$item["avoid"]." and `hands`=".$item["hands"]." and `speed`=".item$["speed"]." and `jump`=".$item["jump"]." and `owner`='mm'",$connsql);
请问有没有什么语法错误。老是提示 $ 错误