By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,826 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,826 IT Pros & Developers. It's quick & easy.

min and max

P: n/a
I wish to assign a variable name to the MIN and MAX values of a field
in a table. The type is int(7).

I am extracting the field with many others with the following code
from a php call.

$ml_collect='SELECT * FROM ml_lopp LEFT JOIN scfmforening ON
(scfmforening.scfmnum=ml_lopp.scfmnum) LEFT JOIN ml_newtidplats ON
(ml_newtidplats.loppnum=ml_lopp.loppnum) ORDER BY date1,
ml_lopp.loppnum';

$ml_upg=mysql_query($ml_collect);

mysql_close();

The field is contained within the table ml_lopp and it is called
loppnum

I have been trying combinations of this to extract the min and max of
the field from the $ml_upg variable which includes all of the data to
be processed.

$lownum=mysql_result($ml_upg,MIN('loppnum'));
$hghnum=mysql_result($ml_upg,MAX('loppnum'));;

.... of course the syntax is incorrect

and I am very greafull of any help in this matter.

Garry Jones
Sweden

Feb 7 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
GarryJones wrote:
I wish to assign a variable name to the MIN and MAX values of a field
in a table. The type is int(7).

I am extracting the field with many others with the following code
from a php call.

$ml_collect='SELECT * FROM ml_lopp LEFT JOIN scfmforening ON
(scfmforening.scfmnum=ml_lopp.scfmnum) LEFT JOIN ml_newtidplats ON
(ml_newtidplats.loppnum=ml_lopp.loppnum) ORDER BY date1,
ml_lopp.loppnum';

$ml_upg=mysql_query($ml_collect);

mysql_close();

The field is contained within the table ml_lopp and it is called
loppnum

I have been trying combinations of this to extract the min and max of
the field from the $ml_upg variable which includes all of the data to
be processed.

$lownum=mysql_result($ml_upg,MIN('loppnum'));
$hghnum=mysql_result($ml_upg,MAX('loppnum'));;

... of course the syntax is incorrect

and I am very greafull of any help in this matter.

Garry Jones
Sweden
Garry,

$ml_upg is a result set - it does not 'contain the results' - rather it
is an anchor used to retrieve the result sets.

You can retrieve the results one at a time, checking each retrieved row
to see if you have a larger or smaller value than previously retrieved
(or read everything into an array and find the min and max values that
way). Alternatively, you can issue another SQL statement to get the min
and max values of the field.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.