I'm new in PHP language and i doing a task now. I have to take two queries with onclick function. When i click "Best rate" to call the rows from the table ordered by rate and when i click "All reviews" to call them by date created. Do i need to use ajax or there is better way to do it ?
<?php
$posted = false;
if(isset($_POST['add']))
{
$posted = true;
$email = $_POST['email'];
$name = $_POST['name'];
$rate = $_POST['rate'];
$comment = $_POST['comment'];
$dth = date("Y-m-d H:i:s");
$q = "INSERT INTO reviews(email, name, rate, comment, date_created) VALUES ('$email', '$name', '$rate', '$comment', '$dth')";
$k = mysqli_query($con,$q);
}
?>
<body>
<p>Best rate</p><?php
$select_reviews = "SELECT comment, rate FROM reviews ORDER BY date_created DESC LIMIT 4" or die("Не може да изпълни заявката");
$run_reviews = mysqli_query($con, $select_reviews);
while ($review = mysqli_fetch_assoc($run_reviews)){
$post_review = $review['comment'];
$post_rate = $review['rate']
?>
<div class='comment'> <?php echo $post_review; ?></div>
<div class='rate'> <?php echo $post_rate; ?> </div>
<div>-----------------</div>
<?php
}
?>
Here is the code where i make the query and where the reviews are ordered by date. I want to make it when i click "Best rate", the reviews to reorder by rate.