1

あなたの助けが必要です。id と numpos の 2 つの列を持つテーブルがあります。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 に答える