Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 years ago.
使用 mysql_insert_id 获取最后插入的 id。
“从成员中选择 count(id) 作为lastid” 在许多情况下并不意味着最后一个 id。
“从成员中选择 count(id) 作为lastid”
Use mysql_insert_id to get the last inserted id.
"select count(id) as lastid from members" does not mean the last id for many cases.
"select count(id) as lastid from members"
假设 members.id 是一个 AUTO_INCRMENT 字段,您可以使用 mysql_insert_id() 删除一些内容:
members.id
AUTO_INCRMENT
mysql_insert_id()
//Create INSERT query $qry = "INSERT INTO members(email, passwd) VALUES('$email', '$password')"; $result = mysql_query($qry); //find lastid from members $lastid = mysql_insert_id(); //Insert lastid to Companies $insertit = mysql_query("INSERT INTO companies( id, name) VALUES('$lastid', '$cname' )");
Assuming members.id is an AUTO_INCREMENT field you can cut a bit out using mysql_insert_id():
AUTO_INCREMENT
统计表中的总记录并不能保证它是最后一个id。更好的选择是获取 id 列的最大值:
SELECT MAX(id) AS lastid FROM member
但我认为最好的选择是使用 mysql_insert_id 函数:
$qry = "INSERT INTO members(email, passwd) VALUES('$email', '$password')"; $result = mysql_query($qry); $lastid = mysql_insert_id();
Counting the total records in the table does not guarantee that it is the last id. A better option is get the max value of the id column:
But the best option I think is to use the mysql_insert_id function:
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(3)
使用 mysql_insert_id 获取最后插入的 id。
“从成员中选择 count(id) 作为lastid”
在许多情况下并不意味着最后一个 id。Use mysql_insert_id to get the last inserted id.
"select count(id) as lastid from members"
does not mean the last id for many cases.假设
members.id
是一个AUTO_INCRMENT
字段,您可以使用mysql_insert_id()
删除一些内容:Assuming
members.id
is anAUTO_INCREMENT
field you can cut a bit out usingmysql_insert_id()
:统计表中的总记录并不能保证它是最后一个id。更好的选择是获取 id 列的最大值:
但我认为最好的选择是使用 mysql_insert_id 函数:
Counting the total records in the table does not guarantee that it is the last id. A better option is get the max value of the id column:
But the best option I think is to use the mysql_insert_id function: