0
I’ll try to explain it better, like this, by listing something from the bank with DESC id shows something like this:
id:1
id:2
id:3
id:4
id:5
but I want it to be displayed like this:
id:5
id:4
id:3
id:2
id:1
In this case using ORDER BY id ASC will not help me because I need to list several data and with this, the last id’s will not appear if I give a LIMIT!.
For anyone who wants to see a piece of the code:
public function quadroAlunos($id){
$this->Query = $this->Conexao->prepare("SELECT * FROM quadroAlun ORDER BY ? DESC");
$this->Query->bind_param("s",$id);
$this->Query->execute();
$this->ResultadoUser = $this->Query->get_result();
while($this->Listar = $this->ResultadoUser->fetch_assoc()):
echo "<strong class=aluno>".$this->Listar["nick"].":</strong>"; //Recupera nick
echo "<span class=mensagem>".$this->Listar["mensagem"]."</span>"; //Recupera Mensagem
echo "<span class=hora>".$this->Listar["data"]."</span>"; //Recupera hora da postagem
echo "<br /><br />"; //Quebra de linhas
endwhile;
}
It would be good to [Dit] the question and put the relevant part of the code to analyze. Explain the result you want to get, which is easier. And with DESC the result can’t be what you said, there’s something wrong there.
– Bacco
All right, I edited!
– Otavio Fagundes
There is a problem in your code, you are passing a value where it should be a column name. With this ? there will never work ORDER. You are ordering with a fixed value. (the ID passed will always be the same)
– Bacco
Like this, the data is being listed from the bottom up, the bottom is the last id’s and the top is the first id’s, this listing like a chat, the chat you know that lists the last messages from the bottom up, being the ones below the new messages and the ones above the old ones understood ? I want to reverse this
– Otavio Fagundes
They are down because this order is completely meaningless. You have to put the name of the column in the order, and not pass a value to it. This Binding there does not work as you imagine. Put ORDER BY id DESC that works (and get this Binding out of there, which is not helping you at all).
– Bacco
it really worked, vlw, there was a time I needed you to list this listing just now and I couldn’t kkkk
– Otavio Fagundes
If you need to change the column you are sorting, you need to do it with strings
"SELECT * FROM quadroAlun ORDER BY $coluna"
- but you have to be careful not to allow SQL injection into $column. There could callquadroAlunos('nome')
, for example, if you want by name, andquadroAlunos('id DESC')
by id and reversed. But before complicating, finish working by ID right, not to make confusion.– Bacco