Good morning,
I can not find a way to do the following. I need to make a query to a database that orders me first with a criterion, and after all the results with this first criterion, that the rest and computer go by the date of the last edition.
To try to clarify the problem a bit. It is a table that loads all the threads of a forum. In the forum I want you to first show me those threads that are "fixed", regardless of the date of the last edition, and then the rest, ordered by the date of the last edition.
I'm trying with this code but it does not return anything to me:
$statement = $conexion->prepare("SELECT * FROM (SELECT * FROM comentarios WHERE chincheta = 1 ORDER BY fecha_comentario) t comentarios WHERE foro = :foro AND subforo = :subforo AND en_que_hilo = :en_que_hilo AND chincheta = 0 ORDER BY fecha_edicion DESC LIMIT $inicio, $post_por_pagina");
$statement->execute(array(":foro" => $foro, ":subforo" => $subforo, ":en_que_hilo" => 0));
$todos_los_hilos = $statement->fetchAll();
I do not know if it is possible to do it ... or I have to do two different queries, that way I would know how to do it, but the issue of paging would be complicated, so I want to get all of them out of a single query if possible.
EDIT:
I am using the following code:
$statement = $conexion->prepare("SELECT * FROM comentarios WHERE foro = :foro AND subforo = :subforo AND en_que_hilo = :en_que_hilo ORDER BY chincheta DESC, fecha_edicion DESC LIMIT $inicio, $post_por_pagina");
$statement->execute(array(":foro" => $foro, ":subforo" => $subforo, ":en_que_hilo" => 0));
$todos_los_hilos = $statement->fetchAll();
This way, the fixed threads are shown to me first and then the rest of threads (well up here), but I do not order the threads by the date of the last edition.
I show you an image to try to explain it better. The first thread that comes out is fine, it is the fixed one and I want it to be shown before those that are not fixed, then the rest of the threads go, but as you can see they are not ordered, after the thread you should go the thread that is in 3rd position.