Reputation: 571
I am almost certain that this is a boneheaded question with a very simple answer, but I've been knocking my brain against the desk for the last 30 minutes or so and figured it was time to ask for help.
I need to fetch the current highest existing keyID in the database. Simple! So I did this:
$newIDQ = "SELECT MAX(mediaKey) FROM `imd_media`";
$newIDResult = $con->query($newIDQ);
$row = mysqli_fetch_array($newIDResult);
echo "Highest ID should be: " . $row['mediaKey'];
But it never spits anything out in $row['mediaKey']. It's been awhile since I used mySQL for anything and this is my first tussle with mysqli, so I'm sure I'm just looking right past the answer or misunderstanding something.
Upvotes: 0
Views: 152
Reputation: 85
$newIDQ = "SELECT MAX(mediaKey) FROM 'imd_media'";
$newIDResult = $con->query($newIDQ);
$row = $newIDResult ->fetch_array(MYSQLI_ASSOC);
echo "Highest ID should be: " . $row['mediaKey'];`
Upvotes: 0
Reputation: 4223
Try this:
$newIDQ = "SELECT MAX(mediaKey) AS mediaKey FROM `imd_media`"; // rename the result col
$newIDResult = $con->query($newIDQ);
$row = mysqli_fetch_array($newIDResult);
echo "Highest ID should be: " . $row['mediaKey'];
or this:
$newIDQ = "SELECT MAX(mediaKey) FROM `imd_media`";
$newIDResult = $con->query($newIDQ);
$row = mysqli_fetch_array($newIDResult);
echo "Highest ID should be: " . $row['MAX(mediaKey)']; // your probable current result
Upvotes: 2
Reputation: 157839
$row[0]
will do it I believe.
Always debug your code. Say, for your current problem print_r($row);
can help
Upvotes: 3