Page 1 of 1

ECHO results of a query

Posted: Thu Sep 27, 2007 11:09 am
by lesleye
OK, I am new to PHP, and probably this is an easy answer:

I want to get the max number in a column, then echo that number.

I keep getting errors, and dont know where to begin.

This I know is correct, since I tested it on mysql database:

$q1 = "SELECT max(FENUMBER) from rma ";
$result=mysql_query($q1) or die ("Couldn't execute query Lesley");

This does deliver the maximum number in the column FENUMBER.

I am having problems displaying this. Here is where I am now:

$q1 = "SELECT max(FENUMBER) from rma ";
$result=mysql_query($q1) or die ("Couldn't execute query Lesley");


$row= mysql_fetch_array($result);

extract($row);


echo "$FENUMBER";


Thanks: Lesley

Posted: Thu Sep 27, 2007 11:11 am
by John Cartwright
You generally want to avoid the usage of extract() in this case. All your columns will be returned as an array in $row.

Try this and post the results please,

Code: Select all

$row= mysql_fetch_array($result); 
//add these two lines
echo '<pre>';
print_r($row);

Posted: Thu Sep 27, 2007 11:16 am
by lesleye
Getting better, now I need to get rid of the array.

Here are the results from your post:

Array
(
[0] => 16549
[max(FENUMBER)] => 16549
)



The max number is 16549, however, I would like to just post 16549.

Thanks: Lesley

Posted: Thu Sep 27, 2007 11:29 am
by feyd
$row[0] will contain your information.

Posted: Thu Sep 27, 2007 11:34 am
by lesleye
you are a genius... thanks so much.
I have a lot to learn.

Lesley