Forum Moderators: coopster
The first query gives me a Resource ID #4 result:
$result3 = mysql_query('SELECT * FROM `tracker` ORDER BY `speed` DESC LIMIT 1'); So I added what I found while searching for Resource ID #4:
$result3 = mysql_query('SELECT * FROM `tracker` ORDER BY `speed` DESC LIMIT 1');$result4 = mysql_fetch_object($result3);
I am not getting the results I need, can anyone help?
I also want to get an average of the data in the speed table, but am stuck on the first problem, can someone help with that?
$result3 = mysql_query('SELECT MAX(speed) as speed FROM `tracker`') or die(mysql_error());
$row = mysql_fetch_array($result3);
echo 'Max: '.$row['speed'];
$result3 = mysql_query('SELECT MAX(speed) as speed,AVG(speed) as avg_speed FROM `tracker`') or die(mysql_error());
$row = mysql_fetch_array($result3);
echo 'Max: '.$row['speed'].'<br/>';
echo 'Avg: '.$row['avg_speed'];
:)
$convert = 1.15077945; //convert knots to mph
$result3 = mysql_query('SELECT MAX(speed) as speed1,AVG(speed) as avg_speed FROM `tracker`') or die(mysql_error());
$row = mysql_fetch_array($result3);
//$time1 = $row['time1'];
$math = $row['speed1'] * $convert; //convert max speed to mph
$math1 = $row['avg_speed'] * $convert; //convert avg speed to mph
echo 'Maximum Speed: '.round($math, 1).'<br/>';
echo 'Average Speed: '.round($math1, 4);
//echo $time1;
I tried modding the query to:
$result3 = mysql_query('SELECT MAX(speed) as speed1,AVG(speed) as avg_speed , time1(time) FROM `tracker`') or die(mysql_error());
I guessing the max speed query will have to be split fromt the avg query, but the syntax isn't working for me.