Welcome to WebmasterWorld Guest from 54.226.189.112

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problem retrieving MIN value from MYSQL statement

     

Robert Poole

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

5+ Year Member



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.

barns101

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

5+ Year Member



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

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

Robert Poole

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

5+ Year Member



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

Thanks for the effort though.

Habtom

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

WebmasterWorld Senior Member 10+ Year Member



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.

Robert Poole

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

5+ Year Member



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

Habtom

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

WebmasterWorld Senior Member 10+ Year Member



I am glad you sorted it out.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month