I'm searching a query to find the last ID in a table.
I already have tried these two query's
$querycustomerid="SELECT IDCustomer FROM tblCustomer ORDER BY IDCustomer DESC LIMIT 1";
$newid = mysql_query($querycustomertid) or die ("Error in : $querycustomerid. ".mysql_error()) + 1;
$querycustomerid="SELECT MAX(IDCustomer) FROM tblCustomer";
$newid = mysql_query($querycustomerid) or die ("Error in : $querycustomerid. ".mysql_error()) + 1;
but when i echo $newid in php i get back Resource id #3
mysql_query()
returns a MySQL resource. To display the contents of the resource, you can fetch the the result and display it like this:
// For the first query:
$row = mysql_fetch_row( $newid );
echo $row[0]; // To display the first column of the result set.
Besides you're using deprecated mysql_*
functions, the query result of mysql_query()
function is not a number, string, array etc. You must fetch this query result for example using mysql_fetch_row()
function.
Instead this deprecated library consider using mysqli extension or the PDO.