Include GROUP BY ID In my Mysql statement
I implemented a solution to filter my table, but that also made me lose one of the core functionality I wanted. GROUP BY ID DESC so that the latter are placed at the top.
The first time you view the table without any filters, I would like it to be GROUP BY ID DESC as well, but I can't seem to get the way to set up the filters. Any way to get around this? My code is below
<?php
// Check connection
require '../inc/connection.php';
//Select All from Game
$result_else = "SELECT * FROM game WHERE listDate >= NOW() - INTERVAL 1440 MINUTE ";
//Search Function
if (isset($_POST['search'])) {
$search_term = mysqli_real_escape_string($con, $_POST['search_box']);
$result_else .= "AND Region LIKE'%{$search_term}%'";
$result_else .= "OR gameType LIKE'%{$search_term}%' GROUP BY id DESC LIMIT 25";
}
?>
If I wanted the original view of the table without any filters to have a GROUP BY ID DESC LIMIT 25, how would I do it?
Thanks for any help
source to share
Yes, you can do
$result_else = "SELECT * FROM game WHERE listDate >= NOW() - INTERVAL 1440 MINUTE ";
//Search Function
if (isset($_POST['search'])) {
$search_term = mysqli_real_escape_string($con, $_POST['search_box']);
$result_else .= "AND Region LIKE'%{$search_term}%'";
$result_else .= "OR gameType LIKE'%{$search_term}%' ";
}
// $result_else .= "GROUP BY id DESC LIMIT 25";
$result_else .= "ORDER BY id DESC LIMIT 25";
But not sure what you are asking GROUP BY
orORDER BY
GROUP BY
groups content.
ORDER BY
orders content in asc
or desc
order
source to share
Maybe this will help you:
<?php
// Check connection
require '../inc/connection.php';
//Select All from Game
$result_else = "SELECT * FROM game WHERE listDate >= NOW() - INTERVAL 1440 MINUTE ";
//Search Function
if (isset($_POST['search'])) {
$search_term = mysqli_real_escape_string($con, $_POST['search_box']);
$result_else .= " AND Region LIKE'%{$search_term}%'";
$result_else .= " OR gameType LIKE'%{$search_term}%' GROUP BY id DESC";
}
$result_else .= " ORDER BY id LIMIT 25";
?>
source to share