Welcome to WebmasterWorld Guest from 50.17.16.177

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problem retrieving MIN value from MYSQL statement

     
9:08 am on Sep 4, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:June 7, 2007
posts:82
votes: 0


Hey there, another problem which I'm sure has a ridiculously easy answer but I just can't get at it.

I'm running an SQL statement to select a minimum value, here it is examplified:

SELECT MIN( time ) FROM `ordertable` WHERE company = 'Example'

and I know this is fine as I've run it in my database and it's all good.

I just can't find a way of printing this result or assigning it to a variable. The usually trusty...

while($row = mysql_fetch_array($result))
{
echo $row['time'];
}

Is just giving me this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/hhip99/public_html/admin/invoicehowards.php on line 111

I've tried about 15 different approaches but haven't had any joy. Would someone please put me out of my misery and hand me the simple solution! Thanks very much.

9:14 am on Sept 4, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 6, 2005
posts:575
votes: 0


I think you need to use SELECT...AS like so:

SELECT MIN( time ) AS `time` FROM `ordertable` WHERE company = 'Example'
9:59 am on Sept 4, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:June 7, 2007
posts:82
votes: 0


Hmm, unfortunately that doesn't seem to have made a difference.

Thanks for the effort though.

10:45 am on Sept 4, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
posts:1867
votes: 0


Is
$result = mysql_query($query);
?

If not set it, if it is, post that part of the code.

Also use the time in quotes `time` as time is a reserved word.

11:09 am on Sept 4, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:June 7, 2007
posts:82
votes: 0


Haha, yes Habtom! That's so funny. Well, I have to laugh to keep from crying :oD

I guess it's going to be one of those weeks!

Thanks for your help

1:55 pm on Sept 4, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
posts:1867
votes: 0


I am glad you sorted it out.