ECHO results of a query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lesleye
Forum Newbie
Posts: 3
Joined: Thu Sep 27, 2007 11:02 am

ECHO results of a query

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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);
lesleye
Forum Newbie
Posts: 3
Joined: Thu Sep 27, 2007 11:02 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$row[0] will contain your information.
lesleye
Forum Newbie
Posts: 3
Joined: Thu Sep 27, 2007 11:02 am

Post by lesleye »

you are a genius... thanks so much.
I have a lot to learn.

Lesley
Post Reply