[英]How can I get the MAX product_id in MySQL & PHP from database table?
[英]Can't get max id from table in mysql using PHP
您好,我想從MySQL表中獲取最大ID號,我寫道:
<?php
$servername='localhost';
$username='root';
$password='';
$databasename='myDB';
$con = new mysqli($servername,$username,$password,$databasename);
$max_id= $con->query('SELECT max(id) from myTable');
echo "<pre>";
print_r($max_id);
echo "</pre>";
但是$ max_id成為對象,輸出像這樣
mysqli_result Object
(
[current_field] => 0
[field_count] => 1
[lengths] =>
[num_rows] => 1
[type] => 0
)
<?php
$servername='localhost';
$username='root';
$password='';
$databasename='myDB';
$con = new mysqli($servername,$username,$password,$databasename);
$result= $con->query("SELECT max(id) from myTable");
$max_id= mysqli_fetch_array($result);
echo "<pre>";
print_r($max_id);
echo "</pre>rrr";
?>
您需要在查詢后獲取結果。 請在這里閱讀手冊: https : //secure.php.net/manual/en/mysqli.examples-basic.php
並且在閱讀正式文檔之前不要問任何問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.