Saturday, 15 February 2014

php - Displaying result of mysql query -



php - Displaying result of mysql query -

i have managed utilize other questions on here in order find median result in table, unsure of how print result.

this php:

$query = "select x.price price_pints x, price_pints y grouping x.price having sum( sign( 1 - sign( y.price - x.price ) ) ) / count( * ) > .5 limit 1"; $result = mysql_query($query) or die(mysql_error()); // print out result while($row = mysql_fetch_array($result)){ echo "the average cost of pint ". $row['type']. " £".$row['x.price(price)']; echo "<br />"; }

the result shows 5 when test sql query in phpmyadmin, doesn't display when echo result.

previously calculated avg , easy print as:

echo "the average cost of pint ". $row['type']. " £".$row['avg(price)'];

now stuck how alter .$row[price(price)] ^^^

as comments suggest, consider moving pdo or mysqli, mysql_ commands beingness deprecated.

your php needs read;

echo "the average cost of pint ". $row['type']. " £".$row['price'];

however, i'm wondering expect returned in type column? you're not selecting above, , farther returning 1 single value, , 1 type of course, though you're calculating median on prices.

at least, sql be;

select x.price, x.type price_pints x, price_pints y grouping x.price having sum( sign( 1 - sign( y.price - x.price ) ) ) / count( * ) > .5 limit 1

php sql result median

No comments:

Post a Comment