Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with MIN SQL in PHP 1

Status
Not open for further replies.

jimoblak

Instructor
Joined
Oct 23, 2001
Messages
3,620
Location
US
I am having trouble with the following SQL. It works fine directly in MySQL but my PHP web page prints nothing. Does anyone have a clue why this is happening?

Code:
$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT MIN(myfield) FROM `mytable`";
$Result = mysql_db_query ($DBName, $Query, $Link);
while ($Row = mysql_fetch_array ($Result)) {
print ("$Row[myfield]");
}
mysql_close ($Link);

The variables to connect to MySQL are set up properly. Other queries in the page work fine. I'm new to using MIN and this may be the problem.

- - picklefish - -
 
I found that the print line of

Code:
print ("$Row[0]");

seems to work. Suggestions for alternate print lines are still welcome.

- - picklefish - -
 
Suggestion:

I would assign an ALIAS to the returned field:
Code:
SELECT MIN(myField) AS minimum FROM `myTable`
Then you can access it as
Code:
$row["minimum"]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top