I have code like this
$mene = date('Y-m-d h:i:s', strtotime('+1 days'));
$now = date('Y-m-d h:i:s');
$qnow = $this->db->query("SELECT pilihan,COUNT(pilihan) as total FROM votes WHERE date_create BETWEEN '$now' AND '$mene' GROUP BY pilihan");
$someArray = [];
foreach($qnow->result_array() as $row){
array_push($someArray, [
$row['pilihan'] => $row['total']
]);
}
$someJSON = json_encode($someArray);
echo $someJSON;
And this for result
[
{
"1": "213"
},
{
"2": "444"
}
]
How to make this result to single array, so result will be
[
{
"1": "213",
"2": "444"
}
]
Please help to resolve that, Thank you.
$nowis interpolated, and although in this contrived example it's not user data, all it takes is switching that with$now = $_GET['date']and you're in deep trouble. Sometimes these variables are defined in distant parts of the system and passed in so it's never obvious what is or isn't safe. That's why using placeholder values for everything, regardless of origin, is important.echo $someJSON;toecho $config['db']['password'];you get in trouble too. So there are no SQL injection bugs. There might be, if he change the code.