0
How do I make this select display according to what is selected there among the options 'Most recent, Rating, Utility'?:
The most recent would be the last comments added!
The Evaluation would be the comments that had more positive rating in stars and would download, for example 5, 4, 3 etc...
And Utility would be the most like comments.
Normal comment display:
$selecionarComentarios = $conexao->prepare("SELECT a.id_mark, a.id_user, a.comment, a.rate, a.id, a.active, b.name, b.avatar FROM tb_comment a, users b WHERE a.id_user=b.id AND a.id_mark = :post_id ORDER BY id DESC LIMIT $start_pg, $amount_pg");
$selecionarComentarios->bindParam(':post_id',$post_id, PDO::PARAM_INT);
$selecionarComentarios->execute();
Via GET got what I wanted!!
if (isset($_GET["op_com"]))
{
$op_com = $_GET["op_com"];
if($op_com=="recent")
{
$select_comment = "SELECT a.id_mark, a.id_user, a.comment, a.rate, a.id, a.active, b.name, b.avatar FROM tb_comment a, users b WHERE a.id_user=b.id AND a.id_mark = :post_id ORDER BY active DESC LIMIT ".$start_pg.", ".$amount_pg."";
}
if($op_com=="rating")
{
$select_comment = "SELECT a.id_mark, a.id_user, a.comment, a.rate, a.id, a.active, b.name, b.avatar FROM tb_comment a, users b WHERE a.id_user=b.id AND a.id_mark = :post_id ORDER BY rate DESC LIMIT ".$start_pg.", ".$amount_pg."";
}
if($op_com=="good")
{
$select_comment = "SELECT a.id_mark, a.id_user, a.comment, a.rate, a.id, a.active, a.good, b.name, b.avatar
FROM tb_comment a, users b
WHERE a.id_user=b.id AND a.id_mark = :post_id ORDER BY good DESC LIMIT ".$start_pg.", ".$amount_pg."";
}
}
else
{
$select_comment = "SELECT a.id_mark, a.id_user, a.comment, a.rate, a.id, a.active, b.name, b.avatar FROM tb_comment a, users b WHERE a.id_user=b.id AND a.id_mark = :post_id ORDER BY id DESC LIMIT ".$start_pg.", ".$amount_pg."";
}
You can use Javascript to only rearrange comments. Making a new query or a call to a php resource just for this, at least in my opinion is unnecessary. Since there is no code to base and give an answer, stay there as a comment a way I would :)
– Renan Gomes
Orde by in consultation?
– rray
I’ll post the PHP code to display those comments there.
– William Alvares
@rray Ala posted the SELECT that I use to pull the current comment from the photo.
– William Alvares