Table Name in JSON Encoded Array

Discussion in 'PHP' started by scottlpool2003, Dec 13, 2013.

  1. #1
    I'm trying to write a script to accept data from an iPhone app onto a webpage. The data is a user signup. Once the user is signed up, I need to throw back in JSON a success message, the users ID and the table name like this:

    I need to list the table name within a custom JSON encoded array like this:
    
    {
    "users": [
    { "success":"true" ,"userID":".$row['userID']."}
    ]
    }
    
    PHP:
    This is what I have so far, but I'm really struggling to get the table name within the JSON array but outside of the variables;
    
                //Account created, generate success response
                $message = array(
                     'success'=>'true',
                    'userID'=>''.$row['$userID'].''
                    );
                echo json_encode($message);
            }
    
    PHP:
    It looks like this:


     
    scottlpool2003, Dec 13, 2013 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $message = array(
        'users' => array(
            'success'=>'true',
            'userID'=>''.$row['$userID'].''
        )
    );
    echo json_encode($message);
    
    PHP:
    This should do it.
     
    nico_swd, Dec 13, 2013 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    Nope, I need it to be in the square brackets like this:

    {
    "users": [
    { "success":"true" ,"userID":".$row['userID']."}
    ]
    }
    Code (markup):
     
    scottlpool2003, Dec 13, 2013 IP
  4. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #4
    Managed to get it working with:

    
                //Account created, generate success response
                $message = array(
                "users" => array (array(
                'success'=>'true',
                'userID'=>''.$row['userID'].''
                )));
    echo json_encode($message);
    
    PHP:
     
    scottlpool2003, Dec 13, 2013 IP