我需要你的帮助,我有一个表有两列,一个id和numpos,我希望id和numops具有相同的结果。
例如:
$cnx = mysql_connect( "localhost", "root", "" );
$db = mysql_select_db( "maincourante" );
$sql = mysql_query("INSERT INTO ops (id) values('')");
$req = mysql_query("SELECT LAST_INSERT_ID() as id FROM ops");
$data = mysql_fetch_array($req);
$upd = mysql_query("UPDATE `ops` SET `numops`=`idops` WHERE `idops`=$data");
mysql_query($upd, $cnx) or die(mysql_error());
mysql_close();`
感谢您的帮助
答案 0 :(得分:0)
试试这个:
这适用于mysql:
INSERT INTO ops (`numops`) VALUES ((SELECT LAST_INSERT_ID())+1);
适用于php:
mysql_query("INSERT INTO ops (`numops`) VALUES (0)");
mysql_query("UPDATE ops `numops` ='".mysql_insert_id()."' WHERE `id` = '".mysql_insert_id()."'");
或者
mysql_query("INSERT INTO ops (`numops`) VALUES ('".mysql_insert_id()."')");
// this will only works if there is the same query executed before this.