Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old June 3rd, 2003, 02:55 PM
Lizogg Lizogg is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Independence MO
Posts: 11 Lizogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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;

Reply With Quote
  #2  
Old June 3rd, 2003, 03:08 PM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
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:

php Code:
Original - php Code
  1. $row = mysql_fetch_row($result);
  2. echo $row['avg_submit'];


Reply With Quote
  #3  
Old June 3rd, 2003, 03:19 PM
Lizogg Lizogg is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Independence MO
Posts: 11 Lizogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: SQL AVG Results Help

Thank you very much! I'll give it a try

Reply With Quote
  #4  
Old June 3rd, 2003, 04:00 PM
Lizogg Lizogg is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Independence MO
Posts: 11 Lizogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #5  
Old June 3rd, 2003, 04:27 PM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: SQL AVG Results Help

Are you still using the code you supplied in the first post?

Reply With Quote
  #6  
Old June 3rd, 2003, 05:35 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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'];

Reply With Quote
  #7  
Old June 3rd, 2003, 05:45 PM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: SQL AVG Results Help

My bad...change:

$row = mysql_fetch_row($result);

to:

$row = mysql_fetch_assoc($result);

Reply With Quote
  #8  
Old June 3rd, 2003, 05:49 PM
Lizogg Lizogg is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Independence MO
Posts: 11 Lizogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: SQL AVG Results Help

Yeah!! It works. Thanks again.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > SQL AVG Results Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT