I have query:
SELECT * FROM members ORDER BY ( firstColumn / anotherColumn ) DESC
Now I'm printing this:
return $query['firstColumn'] / $query['anotherColumn'];
Is it possible to print divided result without any php tricks? For example return $query['dividedColumns'];
Column Alias will solve your problem, you can change your query to:
SELECT members.*,
( firstColumn / anotherColumn ) AS `divided_amount`
FROM members
ORDER BY divived_amount DESC;
You can do it directly in the query, and use that result as the ORDER BY
argument too.
SELECT *, firstColumn/anotherColumn as dividedColumns
FROM members
ORDER BY dividedColumns DESC
Now you can use it as $query['dividedColumns']
in PHP.
You can try this
SELECT *, (firstColumn/anotherColumn) AS dividedColumns FROM members ORDER BY ( firstColumn / anotherColumn ) DESC