Simple mysql_result php-sql query

Hi guys, im intermediate SQL / PHP Dev, but I never did this, so I lost a bit.

Trying to grab the MAX column number of an INT column. When I run the query in PHPMYADMIN, it works fine, but when I put it in my PHP code, it keeps returning 0. I think my problem is that I don’t know how to extract it from the query correctly. In particular, I use mysql_result, but after reading its syntax, I don't know if you can do it this way.

Here is what i got

$query="SELECT MAX(`imageOrder`) FROM images where `gallery` = '$originalGallery'";
$result=mysql_query($query);    
$num=mysql_numrows($result);

I know the above works, but here I am lost. How to get MAX ( imageOrder) in a PHP variable?

$topOrder=mysql_result($result,0);

Does not work

$topOrder=mysql_result($result,$i,MAX(`imageOrder`));

Doesn't work (BTW loop here)

, , , , ... Im .... 2

?

Craig

+3
4

:

$row = mysql_fetch_row($result);

echo $row[0]; // value

[0] .

0

:

$query = "SELECT MAX(`imageOrder`) as maximages FROM images where `gallery` = '$originalGallery'";
$result = mysql_query($query);    
$num = mysql_fetch_assoc($result);

echo $num['maximages'];
+3
$query = "SELECT MAX(...) AS maximum ...";
$result = mysql_query($query) or die($query);
$row = mysql_fetch_assoc($result);

echo $row['maximum'];

Or, if you want to get directly to a variable:

list($maximum) = mysql_fetch_row($result);
0
source

I could be completely wrong, but from my head you need to get the result, as if it were a string using mysql_fetch_assoc()or something like that.

0
source

All Articles