while ($row = mysql_fetch_array($eventchoices)) {
echo $row['res_name']. " and " .$row['event_name'];
echo "<br>";
}
想要显示最后插入的行,这当前获取数组中的所有内容,我尝试像这样使用 mysql_insert_id()
mysql_insert_id($row);
和其他方法(例如在 while 循环中使用它)所有尝试都会返回错误。
非常感谢您的帮助
最佳答案
mysql_insert_id()
仅当插入记录到表中(带有自动增量列)时才有效。它不会通过 SELECT 语句获取行的 ID。您必须在查询中执行此操作。
仅供引用,新代码不应使用 mysql_* 函数。它们不再维护,社区已开始 deprecation process 。请参阅red box ?相反,您应该了解 prepared statements并使用 PDO或 MySQLi 。如果您无法决定,this article将有助于选择。如果你想学习,这里是 good PDO tutorial .
关于php - 是否可以将 mysql_insert_id() 与 while 循环一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11769847/