2

我做错了什么,我试图从表中获取最后一个record_id,在第一条语句将它插入我的表之后。我似乎只是打印用于显示最后一个 id 的代码?

      SELECT CURRVAL (pg_get_serial_sequence('sheet_tbl','sheet_id'))";

代码在这里

  else {
        echo 'Record added';
        $sql = "INSERT INTO sheet_tbl (site_id,  eventdate, eventtime, username, additionalvolunteers) VALUES ('$_POST[site_id]','$_POST[eventdate]','$_POST[eventtime]', '$username','$_POST[additionalvolunteers]')";

        echo $sql; //Just so I can see what is getting sent
        $result = pg_query($sql);

        $sheet_id_pull = "SELECT CURRVAL (pg_get_serial_sequence('sheet_tbl','sheet_id'))";
        echo $sheet_id_pull; //This is where im having the issue with the above line.
}
4

1 回答 1

2

也许

echo pg_query($sheet_id_pull);

代替

echo $sheet_id_pull;

或者

$sheet_id_pull = pg_query("SELECT CURRVAL (pg_get_serial_sequence('sheet_tbl','sheet_id'))");
echo $sheet_id_pull;

另请阅读this问题。它有更好的方法来获取插入的 id。

于 2013-07-26T08:49:44.717 回答