|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL AVG Results Help
I'm new at this and am having problems displaying the results of my AVG SQL query. When I check the database directly, I am getting the correct answer from avg_submit. When I try to display avg_submit using php, the browser displays: "Resource id #2" instead of the integer. I'm sure it's probably an easy problem to solve but I dont' know php well enough to figure it out and I can't find it in my book. Any help would be very appreciated.
print "Results: <br>"; $sql = 'SELECT AVG( answer ) AS avg_submit FROM `int_response_table` WHERE question_id = '3' AND survey_id = '3''; $result = mysql_query($sql, $conn) or die(mysql_error()); print $result; |
|
#2
|
|||
|
|||
|
RE: SQL AVG Results Help
rather than trying to print out $result, you need to fetch your result from $result. You see, $result is just a 'pointer' to your results from the database. Try using the following after the code you supplied:
|
|
#3
|
|||
|
|||
|
RE: SQL AVG Results Help
Thank you very much! I'll give it a try
|
|
#4
|
|||
|
|||
|
RE: SQL AVG Results Help
Using the code you supplied, there's now nothing showing on the screen. Is there something else I need to do with my database?
|
|
#5
|
|||
|
|||
|
RE: SQL AVG Results Help
Are you still using the code you supplied in the first post?
|
|
#6
|
|||
|
|||
|
RE: SQL AVG Results Help
Yes, this is what the code looks like now:
print "Results: <br>"; $sql = 'SELECT AVG( answer ) AS avg_submit FROM `int_response_table` WHERE question_id = '3' AND survey_id = '3''; $result = mysql_query($sql, $conn) or die(mysql_error()); $row = mysql_fetch_row($result); echo $row['avg_submit']; |
|
#7
|
|||
|
|||
|
RE: SQL AVG Results Help
My bad...change:
$row = mysql_fetch_row($result); to: $row = mysql_fetch_assoc($result); |
|
#8
|
|||
|
|||
|
RE: SQL AVG Results Help
Yeah!! It works. Thanks again.
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > SQL AVG Results Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|