Ouick question! How do you run a query to find the highest number in a field, using PHP and MySQL?
ie:
Code: Select all
A B C
1 a v
1 g t
2 b j
3 y u
3 o iThank you in advance.
Clinton
Moderator: General Moderators
Code: Select all
A B C
1 a v
1 g t
2 b j
3 y u
3 o iCode: Select all
SELECT MAX(A) FROM tableNameCode: Select all
SELECT MAX(A) FROM table;Code: Select all
// 1. check wishlist table for latest numWishlist for numUserID
require_once('dfdconx/bus.php');
mysql_select_db($database_dfdbiz, $dfdbiz);
$query_rstCheckWishList = ' SELECT MAX(numWishlist)
FROM mtblwishlist
WHERE numUser = "'.$numUserID.'"';
$rstCheckWishList = mysql_query($query_rstCheckWishList, $dfdbiz) or die(mysql_error());
// 2. add 1 to numWishlist
$numWishlist = (int)$rstCheckWishList + 1;
echo $numWishlist.'<br>';Code: Select all
// 1. check wishlist table for latest numWishlist for numUserID
require_once('dfdconx/bus.php');
mysql_select_db($database_dfdbiz, $dfdbiz);
$query_rstCheckWishList = 'SELECT MAX(numWishlist) as maxWishList
FROM mtblwishlist
WHERE numUser = "'.$numUserID.'"';
$rstCheckWishList = mysql_query($query_rstCheckWishList, $dfdbiz) or die(mysql_error());
$line = mysql_fetch_array($rstCheckWishList, MYSQL_ASSOC);
$maxWishList = $line['maxWishList'];
// 2. add 1 to numWishlist
$numWishlist = (int)$maxWishList + 1;
echo $numWishlist.'<br>';