This question already has an answer here:
It may sound like noob question but I think ive tried everything and ive been stuck for weeks with this not making any progress.
This is my working code:
//$connect holds my db login details so ill hide it
$query = '
SELECT *,UNIX_TIMESTAMP(CONCAT_WS(" ", ranking_data_date, ranking_data_time)) AS datetime
FROM tbl_ranking_data
ORDER BY ranking_data_date ASC, ranking_data_time ASC LIMIT 60
';
$result = mysqli_query($connect, $query);
$rows = array();
$table = array();
$table['cols'] = array(
array(
'label' => 'Date Time',
'type' => 'datetime'
),
array(
'label' => 'Position',
'type' => 'number'
)
);
while($row = mysqli_fetch_array($result))
My problem is that it always selects same data (and all of it) from database.
To fix it, ideally it would be to insert where clause for example:
WHERE user_id=$id_of_current_user
But I can't enter that or anything or i will get error.
Basically code same as above but with this difference:
//$connect holds my db login details so ill hide it
$query = '
SELECT *,UNIX_TIMESTAMP(CONCAT_WS(" ", ranking_data_date, ranking_data_time)) AS datetime
FROM tbl_ranking_data
WHERE user_id=$id_of_current_user
ORDER BY ranking_data_date ASC, ranking_data_time ASC LIMIT 60
';
Shows this error:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /files/phpfile.php on line 32
My understanding: query fails and it returns false (thats why error talks about boolean) instead of array ($result) but it shouldnt fail!
it only fails if I add WHERE condition.
Any help appreciated.
How can I insert where clause to this code?
</div>