1

我需要你的帮助,我有一个包含两列的表,一个 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();`

感谢您的帮助

4

1 回答 1

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.
于 2012-11-15T05:16:34.973 回答