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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Query

Status
Not open for further replies.

james0816

Programmer
Jan 9, 2003
295
US
ok...this code works in mysql....but not displaying properly in PHP.

$result3 = mysql_query("select avg(s) as avs, avg(f) as avf from results where dcode='1' and yr='2005'", $connection);

echo mysql_result($result3,"avs");

This statement will display avs correctly. However, If I change it fo avf....it still displays the result from avs????

i am soooo confused. Can someone shed some light on this?

thx
 
It would be better (IMHO) to write:
Code:
$q = "select avg(s) as avs, avg(f) as avf from results where dcode='1' and yr='2005'";
$rs = @mysql_query($q) or die('Problem with query. ' . mysql_error());
$rw = @mysql_fetch_assoc($rs);
echo 'avs: ' . $rw['avs'] . "<br>\n";
echo 'avf: ' . $rw['avf'] . "<br>\n";
It's much clearer as to what the code is doing.

Ken
 
i have it working now but even more confused.

i wound up coding it like this:

echo mysql_result($result3,0,0) for avs
echo mysql_result($result3,0,1) for avf

it displayed fine that way....but why not by name??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top