-1

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

wpercy
  • 9,636
  • 4
  • 33
  • 45
Sleepy
  • 180
  • 3
  • 15
  • 1
    Please provide code and sample output highlighting the problem – Tristan Dec 01 '15 at 18:12
  • What is in line 5? Anyways, the code you shared does not echo anything, you probably altered the algorithm when copying it here. – RandomSeed Dec 02 '15 at 12:29
  • oh yes i altered here & line 5 is the same as the others thanks for your help the issue is fixed something about the data character (like ë, î...) in the database i either change the data or do as suggested in response comment – Sleepy Dec 02 '15 at 18:25

1 Answers1

0

Solved
The isssue was from the data.
Where (as far as i guessed) it couldn't be encoded because it had a character like ë, ï, etc..

Sleepy
  • 180
  • 3
  • 15
  • It's not "unreadable", `json_encode` merely expects its input to be UTF-8 encoded, and apparently those characters aren't. Fix your database interaction. http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – deceze Dec 02 '15 at 10:38
  • Well i have tried that following the instructions in the link you just provided and it the word with the character like é are not properly shown – Sleepy Dec 02 '15 at 12:19