Jump to content

How can I save the my database contents to json


Recommended Posts

This is my script:

 

I'm trying to save the contents of a database to json

I've getting the database contents to echo out but can get it encoded into json.

 

How can I do this or what am I doing wrong here?

 

<?php
echo '<link rel="stylesheet" href="css/styles.css" />';

    // Create connection
    //$connection = mysqli_connect("localhost","root","","finalprojectapp"); //Localhost Connection

    //Check Connection
    if(mysqli_connect_errno($connection)){
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }else{
        echo "Success, Connection Achieved";
    }

    $result = mysqli_query($connection,"SELECT * FROM member");

    while($row = mysqli_fetch_array($result))
      {
      echo "<br/><br/>ID: <p>" . $row['id'] . "</p>
             Phone Number: <p>" . $row["phoneNumber"] . "</p>
           First Name: <p>" .  $row["firstName"] . "</p>
           Last Name: <p>" . $row["lastName"] . "</p>
           Profile Picture: <p>" . $row["profilePicture"] . "</p>
           Photo: <p>" . $row["photo"] . "</p>
           Video: <p>" . $row["video"] . "</p>
           Text: <p>" . $row["text"] . "</p>
           Call: <p>" . $row["call"] . "</p>
           Activity: <p>" . $row["activity"] . "</p>
           Latitude: <p>" . $row["latitude"] . "</p>
           Longitude: <p>" . $row ["longitude"] . "</p>
           Date: <p>" . $row["date"] . "</p>
           Time: <p>" . $row["time"] . "</p><br/>";
      }

$a = array($row["id"],$row['phoneNumber'],$row['firstName'], "\xc3\xa9");

echo "Normal: ",  json_encode($a), "";

    mysqli_close($connection);

 

Link to comment
Share on other sites

Sorry for not responding straight away. I've just got back from a camping trip.

Also sorry for not wrapping my code in <>.

 

The most important part of the code I need working isn't working:

 

It's this section:

$a = array($row["id"],$row['phoneNumber'],$row['firstName'], "\xc3\xa9");

echo "Normal: ",  json_encode($a), "";

Which is returning this:

Normal: [null,null,null,"\u00e9"]

I want it to return the values stored in my mySQL database and not null but it doesn't seem to be working.

 

Any ideas

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.