As I am creating a web service I am encountering an issue that returns no errors. I get data from tables in a mysql database and I just use json_encode
.
The problem is when it shows results it show all of them as if some lines were invisible. The query works perfectly in mysql but when it's placed in my php code it just doesn't seem to work as intended.
To be more precise some values when added to the array that is passed to the json_encode
make x lines disappear, one of these attributes makes everything disappear.
I rebuilt my query from when I was using where
to joins
and I still have the same issue. I checked if the values value (in both query result & array object separately and they show perfectly)
Update
select m.id , t.teamname HomeTeam, t2.teamname AwayTeam,
from matches m
inner join teams t on m.hometeam_id = t.id
inner join teams t2 on m.awayteam_id = t2.id
this is the query & in the php file
while ($data = $result->fetch(PDO::FETCH_OBJ))
{ $tab_result = array();
$tab_result["MatchId"] = $data->id
$tab_result["HomeTeam"] = $data->HomeTeam;
$tab_result["AwayTeam"] = $data->AwayTeam;
json_encode($tab_result); }
Now this would show some data and I can't figure out why
example of result
{"Matches":[{"MatchId":"1","HomeTeam":"Polen"}]}
{"Matches":[{"MatchId":"2","HomeTeam":"Rusland"}]}
{"Matches":[{"MatchId":"3","HomeTeam":"Nederland"}]}
{"Matches":[{"MatchId":"4","HomeTeam":"Duitsland"}]}
{"Matches":[{"MatchId":"6","HomeTeam":"Ierland"}]}
Notice that id 5 doesn't show and no errors just an empty line but if for example i only fill with the Id all will show, adding hometeam / awayteam or both causes this