I am trying to get a variable in a MySQL query.
$filter = $_GET['fltr'];
require_once('core/dbconnect.php');
if($filter)
{
$limit = 'LIMIT '. $filter;
}
$lastonline = mysql_query("SELECT * FROM logins ORDER BY time DESC GROUP BY username '$limit'");
Now the problem is somewhere where I put '$limit' in the query. That doesn't work, but what is the proper way to do this?
It almost works okay now as I get a result only not the absolute correct one. I changed the code to this:
$filter = $_GET['fltr'];
require_once('core/dbconnect.php');
if($filter)
{
$limit = 'LIMIT '. (int) $filter;
}
$lastonline = mysql_query("SELECT * FROM logins GROUP BY username ORDER BY time DESC {$limit}");
As you can see I had to change GROUP BY and ORDER BY around as that doesnt work. I did put it in that order for a reason, as now it groups by username first but doesnt take the last login out anymore.
Anyone that knows a solution for this last issue in this query?
Thanks for all of your help in advance!