0
I need to sort the result of my search by a value that is outside the query.
For example, in the query I have a field called answer and with this value I make a calculation. But the result of that calculation is not in table.
My query
$search = mysql_query('SELECT * FROM simuladosrespondidos AS sr
JOIN usuarios AS u ON u.idUsuarios = '.$idUsuario.' AND sr.idUsuarios = u.idUsuarios
JOIN questoes AS q ON q.idQuestao = sr.idQuestao WHERE sr.idSimulado = '.$idSimulado.'');
What I do is I take the value of a column called answers and do the calculation on top of it. How to order by that calculation?
Note: The calculation q do actually is the following: I get the value of the answer column. Each user has several answers. If it equals 'C' we are + 1 in a variable here. If it equals 'E' I decrease - 1 and if it equals E I do nothing and at the end of everything I have a value and it is for that value I want to order.
Post as your query. Examples of values to make it easier to view your need.
– Celso Marigo Jr
You are doing your calculation in mysql or php?
– Marco Souza
I edited with my query
– Thiago
Edit again with the result after you do the calculation.
– Marco Souza
I edited the question, guys
– Thiago
Passes more information, if somehow you are saving an array with the calculation of information, right or wrong and final value. You can sort this array with PHP.
– Ricardo Lucas