nec9716 Posted April 24, 2008 Share Posted April 24, 2008 ok here how I have write it: $sql = 'SELECT avg (total) FROM truck '; $results = conn($sql); echo "<tr> <td >$results</td> </tr>"; but that print......Resource id #3 Link to comment https://forums.phpfreaks.com/topic/102752-solved-avg-trouble/ Share on other sites More sharing options...
haku Posted April 24, 2008 Share Posted April 24, 2008 You have to process results from mysql, you can't just use them as is. Here is one way you can get the data you want: $sql = 'SELECT avg (total) FROM truck '; $results = conn($sql); $results = mysql_result($results, 0, 0); echo "<tr> <td >$results</td> </tr>"; Link to comment https://forums.phpfreaks.com/topic/102752-solved-avg-trouble/#findComment-526254 Share on other sites More sharing options...
wrathican Posted April 24, 2008 Share Posted April 24, 2008 you still need to fetch the array afaik. <?php $sql = 'SELECT avg (total) FROM truck '; $results = mysql_query($sql); while ($row = mysql_fetch_array($results)){ $avg = $row['total']; echo "<tr> <td >$avg</td> </tr>"; } ?> Link to comment https://forums.phpfreaks.com/topic/102752-solved-avg-trouble/#findComment-526258 Share on other sites More sharing options...
nec9716 Posted April 24, 2008 Author Share Posted April 24, 2008 just try it and it's work fine .....sometime .....I'm surprise ....but this time ....I'm....... well I feel...... :-X. HAKU ....why you write ",0,0 here ......$results = mysql_result($results, 0, 0);.....? thank you ..... Link to comment https://forums.phpfreaks.com/topic/102752-solved-avg-trouble/#findComment-526260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.