Answer the question
In order to leave comments, you need to log in
How to select last id from sql table?
I need to select the last assigned id from the database when loading the page. Ids are assigned automatically. In phpmyadmin, the code works, but it does not display data on the page (Id must be displayed not on the registration page). Here is my code:
$sql = "SELECT LAST_INSERTED_ID FROM members";
while ($row = mysql_fetch_assoc($sql)) {
echo "<span class='num'>" + $row['id'] + "<span>";
}
Answer the question
In order to leave comments, you need to log in
PHP has a function like mysql_insert_id . I think this is what you need.
PS I beg you, do not use outdated database functions. On kraynyak - mysqli extension. And ideally - PDO
Nothing happens. The page loads without errors, but the result is not displayed anywhere.
$sql = "SELECT LAST_INSERTED_ID FROM members";
$sql = mysql_query ($sql);
while ($row = mysql_fetch_assoc($sql)) {
echo "<span class='num'>" . $row['id'] . "<span>";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question