Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Crypto currency names in the JSON file are saved as "array" in the mysql database. How can I add these names to the column named "Adi"? I need coin names to be added to the database as well. It processes all data into my database in one go, but does not get the coin name (such as BTC _TL, ETH_TL)

view of the database (coin names will appear in the red marked); https://ibb.co/17gvJVR

MY JSON CODES;

{
"BTC_TL": {
"lowestAsk": 303250,
"highestBid": 302951,
"low24hr": 296000,
"high24hr": 310990,
"avg24hr": 303800.18554769,
"volume": 1230.70390836,
"last": 303249,
"change": -1749,
"percentChange": -0.6,
"chartData": [
  
]
},
"ETH_TL": {
"lowestAsk": 9967,
"highestBid": 9956,
"low24hr": 9070,
"high24hr": 10194,
"avg24hr": 9539.62230136,
"volume": 27905.94836496,
"last": 9956,
"change": 799.21,
"percentChange": 8.7,
"chartData":[ [][1]
  
]
},
"XRP_TL": {
"lowestAsk": 2.61,
"highestBid": 2.606,
"low24hr": 2.401,
"high24hr": 2.7,
"avg24hr": 2.50030057,
"volume": 35478235.00648834,
"last": 2.606,
"change": 0.192,
"percentChange": 8,
"chartData": [
  
]
},
"BTC_USDT": {
"lowestAsk": 40829.01,
"highestBid": 40828,
"low24hr": 39200,
"high24hr": 41550.55,
"avg24hr": 40540.35763825,
"volume": 4.27793552,
"last": 40828,
"change": 1225,
"percentChange": 3.1,
"chartData": [
  
]
},

my php codes;

 <?php
      
      $connect = mysqli_connect("localhost", "user", "pass", "dbname"); //Connect PHP to MySQL Database
      $query = '';
      $table_data = '';
      $filename = "coin.json";
      $data = file_get_contents($filename); //Read the JSON file in PHP
      $array = json_decode($data, true); //Convert JSON String into PHP Array
      foreach($array as $row) //Extract the Array Values by using Foreach Loop
      
      {
       $query .= "INSERT INTO tablename(Adi, lowestAsk, highestBid, low24hr, high24hr, avg24hr, volume, last, `channge`, percentChange)  VALUES('".$array."', '".$row["lowestAsk"]."', '".$row["highestBid"]."', '".$row["low24hr"]."', '".$row["high24hr"]."', '".$row["avg24hr"]."', '".$row["volume"]."', '".$row["last"]."', '".$row["change"]."', '".$row["percentChange"]."'); ";  // Make Multiple Insert Query 
       $table_data .= '
        <tr>
   <td>'.$row["low24hr"].'</td>
   <td>'.$row["lowestAsk"].'</td>
   <td>'.$row["highestBid"].'</td>
  </tr>
       '; //Data for display on Web page
      }
      if(mysqli_multi_query($connect, $query)) //Run Mutliple Insert Query
{
 
 echo '<h3>datas</h3><br />';
 echo '
  <table class="table table-bordered">
    <tr>
     <th width="45%">low24hr</th>
     <th width="10%">lowestAsk</th>
     <th width="45%">highestBid</th>
    </tr>
 ';
 echo date('d.m.Y H:i:s');
 echo $table_data;  
 echo '</table>';
 
      }
      ?>
question from:https://stackoverflow.com/questions/65651709/json-file-to-mysql-database-a-column-inserted-as-array

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
107 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...