mysql - Can't we call $result as variable in php -
i have query in php code
$dbc = mysqli_connect('localhost', 'root','', 'delivery') or die('error connecting mysql server.'); $count = "select max(id_pelanggan) pelanggan"; $result = mysqli_query($dbc, $count) or die('error select query'); if (empty($result)) { $id_pelanggan = 1; } else { $id_pelanggan = $result + 1; }
and result
object of class mysqli_result not converted int in c:\xampp\htdocs\delivery\addcustomer.php
whereas in mysql id_pelanggan datatype int. can me make works?
- you try assign query
$id_pelanggan
variable instead of value query. - fetch result using
*_fetch array()
of query - i've changed
if()
condition because$result
won't empty no matter happens. number of result maybe.
put , replace if else
condition:
if(mysqli_num_rows($result) == 0){ /* if found 0 result */ $id_pelanggan = 1; } else { while($row = mysqli_fetch_array($result)){ $maxid = $row["id_pelanggan"]; } $id_pelanggan = $maxid + 1; } /* end of else */
Comments
Post a Comment