error in php coding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
learner001
Forum Newbie
Posts: 3
Joined: Thu Jun 12, 2014 3:39 am

error in php coding

Post 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')));
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: error in php coding

Post 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.
Post Reply