First off my code:
<?php
include($_SERVER['DOCUMENT_ROOT'].'/website/dbConnection.php');
function filterTable($searchquery)
{
$filter_Result = mysqli_query($GLOBALS['connect'], $searchquery);
return $filter_Result;
}
$searchquery = "SELECT Titel, Vorname, Name, Unternehmen, Gruppe FROM mitglieder";
$searchresult = filterTable($searchquery) or die("Tabelle kann nicht angezeigt werden");
echo json_encode($searchresult);
?>
I found multiple posts, the most popular one being this one.
So I tried this:
$filter_Result = mysqli_query($GLOBALS['connect'], 'SET CHARACTER SET utf8', $searchquery);
I also put it before the connect variable and in its own function because I wasn't sure how to utilize it but nothing helped. When I put it as a parameter it actually gave out a parse error.
When I echo out the array before sending it out its perfectly normal. After I use json_encode()
everything gets wiped and I have an Array full of null's. You can see that in the picture below. I echoed out the Array and then I echoed json_encode
with the Array as a parameter. The yellow marked line is the json_encode
one, where you can see that suddenly everything is null.
Anybody know what Im doing wrong?
Edit: Forgot to mention that those are German words in my query. Just ignore those, since the problem doesn't lie in the SQL Query.
Edit 2: The proposed post doesn't answer my question as it isn't a similar problem. The other users problem is working with multidimensional arrays and them returning different results. While it is close to what my Problem was, it wasn't the same Problem and it also wasn't the same solution.