0
我正在嘗試使用表單發佈將行添加到mySQL表。每一行都有一個主要的我打電話給quoteID。提交新表單時,應將其自身添加爲表格中的一行,其quoteID比前面的quoteID大1。它目前看起來是這樣的:mysql_fetch_assoc從主鍵返回數組
<?
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
include 'verify.php';
$con = mysql_connect("localhost","user","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("internal", $con);
$previousOrderID = mysql_query("SELECT * FROM sourcingQuote ORDER BY quoteID DESC LIMIT 1");
$previousOrderID = mysql_fetch_assoc($previousOrderID);
$newOrderID = $previousOrderID['ID'] + 1;
mysql_close($con);
?>
目前有4分排在該表中,用1,2,3 quoteID的和4奇怪的是,如果我嘗試:
<? echo $previousOrderID; ?><br>
<? echo $newOrderID; ?><br>
輸出結果是:
Array
1
爲什麼不是$ newOrderID顯示5?並且值$ previousOrderID 4?
謝謝。
完美:)謝謝! – Hikalea
很高興幫助! – andrewsi