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);

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.