# PHP - Get the highest value in an array

**URL:** <https://forum.kirupa.com/t/php-get-the-highest-value-in-an-array/125911>\
**Category:** Uncategorized\
**Created:** [October 18, 2004, 10:05pm UTC](https://forum.kirupa.com/t/php-get-the-highest-value-in-an-array/125911 "2004-10-18T22:05:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![imagined](https://avatars.discourse-cdn.com/v4/letter/i/a87d85/32.png) [@imagined](https://forum.kirupa.com/u/imagined)\
**Post date:** [October 18, 2004, 10:05pm UTC](https://forum.kirupa.com/t/php-get-the-highest-value-in-an-array/125911/1 "2004-10-18T22:05:28Z")

</div>

Let’s say I have a database(PHOTOALBUM) and a table (ALBUMS) with three columns:

ID, Name, Date

I want a script where it shows me ONLY the highest ID. Let’s say I have 10 names. I want the variable $id to have number 10 inside. Here’s what I have but doesn’t work as I want it to.

I want the last ID so I can have ID + 1 and insert a new ID number.

$sql = “SELECT \* FROM albums”;  
if (!$sql)  
{  
echo(“Could not select data from table”);  
exit();  
}

$result = mysql\_db\_query(‘photoAlbum’, $sql);  
if (!$result)  
{  
echo(“Database query not successful”);  
exit();  
}

$row = mysql\_fetch\_array($result);  
if (!$sql)  
{  
echo(“Could not retrieve array”);  
exit();  
}

$id = $row[“description”];  
if (!$sql)  
{  
echo(“Could not retrieve row”);  
exit();  
}

echo (’\<p\>’ . $id . ‘\</p\>’);

Any suggestions?

Thanks!
