Reputation: 237
if ($resultdetails == FALSE) {
$querynewid = "select * from customer_det order by ID desc limit 1";
$resultnewid = mysql_query($querynewid);
while ($row=mysql_fetch_row($resultnewid)) {
$uid = $row['id'];
echo $uid;
}
}
Is this a valid nested statement to make? It won't echo $uid for some reason?
Upvotes: 0
Views: 96
Reputation: 540
How I usually handle this in php is below:
if ($resultdetails == FALSE) {
$querynewid = mysqli_query($dbc,"select * from customer_det order by ID desc limit 1";) or die (mysql_error());
while ($row = mysqli_fetch_array($querynewid)) {
$uid = $row['id'];
echo $uid;
}
}
A couple things to know is the $dbc is my database connection and that the mysql_error will let you know if its the query that itself that is broken
Upvotes: 1
Reputation: 34867
You should use mysql_fetch_assoc
instead of mysql_fetch_row
. The last one returns a numerical indexed-array, so id
is not a key in that result set. mysql_fetch_assoc
returns an associative array, so the field name is also the name of the key. By the look of your code, that is what you want.
See the difference here and here.
Upvotes: 1