Is there a way to order the prepared sql without preparing another select?
$stmt = $conexao->stmt_init();
$stmt->prepare("SELECT * FROM esc_usuarios WHERE usu_codigo = ?");
$stmt->bind_param("s", $usu_codigo);
$stmt->execute();
I wanna get the data from usu_datacadastro
and then order:
SELECT * FROM esc_usuarios WHERE usu_indicador_codigo = ? ORDER BY usu_datacadastro DESC LIMIT 5
But I already have this data provided by the first sql, I just need to do the order by and echo somewhere.
As mentioned, something like this might help you http://php.net/manual/en/function.usort.php
usort(
$data,
function($arr1, $arr2) {
// descending
return strcmp($arr2['usu_datacadastro'], $arr1['usu_datacadastro']);
});
If you want to preserve the original order of the array, I would suggest adding pointers/references to an array in the order you desire, as opposed to cloning the array.