mysql_fetch_array将值拉入变量

时间:2014-04-10 14:46:02

标签: php mysql sql

我知道这很麻烦,但是到了我的系绳的末端,这应该可行,但我不明白为什么我不能将我的订单表的第一个值放入变量order_id ,任何人都可以看到我的错误吗?

由于

$con = mysql_connect("localhost", "tim", "password");

if (!$con) {
    die('Could not connect: '.mysql_error());
}

$sql = "SELECT TOP 1 order_order_id FROM tbl_order ORDER BY order_id DESC";
$result = mysql_query($sql, $con);

while ($rows = mysql_fetch_array($result)) {
    $order_id = $rows;
}

1 个答案:

答案 0 :(得分:-1)

使用此代码并告诉我它是否有效:

$con = mysql_connect("localhost","tim","password");

if (!$con)
   {
   die('Could not connect: ' . mysql_error());
  }
$sql = "SELECT TOP 1 order_order_id FROM tbl_order ORDER BY order_id DESC";
$result = mysql_query($sql,$con);
if (mysql_num_rows($result)) {
     $rows = mysql_fetch_assoc($result);    
     $order_id = $rows['order_order_id'];    
} else {
     die('No order ID found');
}