我无法递增 id

  • 本文关键字:id php sql web-services
  • 更新时间 :
  • 英文 :


我搜索了许多堆栈溢出问题,但没有帮助。我想通过从 MySQL 表中获取最后一个 id 来增加id

我不想在 MySQL 表中进行自动增量,因为已经有一列是自动递增的。

<?php
include 'db.php';
$created = date('Y-m-d H:i:s');
//$json_data    = array();
$message = array();
$error = array();
if ($_GET['vendor_id'] == "") {
    $message[] = array("message" => "Values Empty");
} else {
    $result = mysqli_query("SELECT loo_id  FROM loo_list ORDER BY loo_id DESC LIMIT 1");
    if ($result) {
        $order_array = mysqli_fetch_assoc($result) or die(mysqli_error());
        //echo $order_array['loo_id'];
    }
    $loo_id = $order_array['loo_id'] + 1;
    $sql = "insert into loo_list(loo_id,name,address,geolocation,price,facility_category,facilities,count,accessbility,image,type,category,created_vendor,days,timings,terms_conditions,vendor_approval,created,warning,url,user_ids,overall,admin_approval,updated)values('" . $loo_id . "','" . $_GET['loo_name'] . "','" . $_GET['address'] . "','" . $_GET['loo_location'] . "','" . $_GET['price'] . "','" . $_GET['facility_category'] . "','" . $_GET['facilities'] . "','" . $_GET['count'] . "','" . $_GET['accessbility'] . "','" . $_GET['image'] . "','Offerers','" . $_GET['category'] . "','" . $_GET['vendor_id'] . "','" . $_GET['days'] . "','" . $_GET['timings'] . "','" . $_GET['terms_conditions'] . "','1','" . $created . "','0','','" . $_GET['user_ids'] . "','" . $_GET['overall'] . "','1','" . $created . "')";
    $res1 = mysqli_query($db, $sql) or die(mysqli_error());
    $message[] = array("message" => "success");
}
$json_data = array("result" => $message);
echo json_encode($json_data);
?>  

试试这段代码。

if(trim($order_array['loo_id']) === ''){ 
 $loo_id = 1; 
}else{
 $loo_id = intval($order_array['loo_id']) + 1;
}

相关内容

  • 没有找到相关文章

最新更新