Note that there are some explanatory texts on larger screens.

plurals
  1. POInset php json encoded array into database
    primarykey
    data
    text
    <p>I need to insert elements of a php encoded array into a database and I'm completely stuck. I have first used json encode to to grab data from the database using an SQL query (which I did successfully) but I now need to be able to do the opposite. If anyone could help I'd greatly appreciate it. It's my second day of work and I'm not doing so well. The following is my code:</p> <pre><code> $UserCoords_Query = "Select Accuracy, Longitude, Latitude, Timestamp FROM UserDetails WHERE UserId =" . $UserID; $UserCoords_result = mysql_query($UserCoords_Query); if (mysql_num_rows($UserCoords_result) == 0) { echo "There are no users with an id of ". $UserID; } else { $EmptyArray=array(); while ($row = mysql_fetch_array($UserCoords_result)) { $Accuracy=$row['Accuracy']; $Longitude= $row['Longitude']; $Latitude=$row['Latitude']; $Timestamp= $row['Timestamp']; $Queue= array('Accuracy:' =&gt; $Accuracy, 'Latitude' =&gt; $Latitude, 'Longitude' =&gt; $Longitude, 'Timestamp' =&gt; $Timestamp); array_unshift($EmptyArray,$Queue); } $ObjectResponse = array('Coords' =&gt; $EmptyArray); echo json_encode($ObjectResponse); $Json_Encoded= json_encode($ObjectResponse); $Json_Decoded= json_decode($Json_Encoded, true); $Update_Query= "INSERT INTO UserDetails (UserId, Accuracy, Latitude, Longitude, Timestamp) VALUES ('".$UserID."','".$Json_Decoded[0] ['Accuracy']."','".$Json_Decoded[0]['Latitude']."', '".$Json_Decoded[0]['Longitude']."','".$Json_Decoded[0]['Timestamp']."')"; mysql_query($Update_Query) or die(mysql_error()); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload