Page 1 of 1

error in php coding

Posted: Thu Jun 12, 2014 3:44 am
by learner001
I am having prob in the 'employee'=>$posts. It is crashing my iphone application. I want to convert 'employee'=>$posts to a string and then pass an if else condition for an input to be true or false according to above coding. How should i do it?

Code: Select all

if(mysql_num_rows($selectemployee))
    {
      while($post = mysql_fetch_assoc($selectemployee)) 
    {
      $posts[] = $post;
    }
              
    header('Content-type: application/json');
    echo stripslashes(json_encode(array('employee'=>$posts)));
    }
    else 
    {
    header('Content-type: application/json');
    echo stripslashes(json_encode(array('employee'=>'No record')));

Re: error in php coding

Posted: Thu Jun 12, 2014 12:16 pm
by requinix
You should do it according to how your app expects the data. Or rewrite the app so it can accept whatever data you're passing to it.
Since we don't know your app, at all, it's pretty hard for us to tell you what you're doing wrong.

Though I can say you shouldn't be running stripslashes() on anything. You could be breaking the JSON.