Save multidimensional array with foreach loop in database

I warite script to extract price and name from website with foreach loop.

    foreach($table_rows as $tr) { // foreach row
    $row = $tr->childNodes;
    if($row->item(0)->tagName != 'tblhead') { // avoid headers
     $data[] = array(
     $trip ['Name' ]= trim($row->item(0)->nodeValue),
     $trip['LivePrice'] = trim($row->item(2)->nodeValue),
     $trip ['Changing']=  trim($row->item(4)->nodeValue),
     $trip ['Lowest']=  trim($row->item(6)->nodeValue),
     $trip['Topest']=  trim($row->item(8)->nodeValue),
     $trip['Time']= trim($row->item(10)->nodeValue),

     );
  }
  }

and then save they in to the database with mysql (no mysqli or pdo) . but only save one record ، If the 5 column provided .

and after each refresh the page save Previous record (i.e repetitive recod)

please see following .

in the database:

id | name | liveprice | changing | lowest | topest | time
1 | lg | 25500 | 05 | 22500 | 22500 | 2014
2 | lg | 25500 | 05 | 22500 | 22500 | 2014
3 | lg | 25500 | 05 | 22500 | 22500 | 2014
database code and php for store data in to the database

     $article = array ();
    mysql_select_db ( "coin", $con );

    "CREATE TABLE `Dadoo`(id INT NOT NULL AUTO INCREMENT,PRIMARY              KEY(id),`title`   VARCHAR(255),`liveprice` VARCHAR(255),`changing`      VARCHAR(255),`lowest` VARCHAR(255),`topest` VARCHAR(255) ENGINE=MyISAM";
    $debugquery = mysql_query("INSERT INTO `Dadoo`(title,liveprice,changing,lowest,topest,time) VALUES ('".$trip['Name']."','".$trip['LivePrice']."','".$trip['Changing']."','".$trip['Lowest']."','".$trip['Topest']."','".$trip['Time']."')");
                    if (!$debugquery)
    {
    die(mysql_error());
    }

now how can I save multidimensional array in the database?

Where is the data coming from, is it coming via an API?

You really need to migrate away from the old and deprecated mysql_* extension as it’s being removed as of PHP7 (which comes out later this year), if your host upgrades to PHP version 7, any scripts that you have that use the old mysql_* extension will be broken.

fixed

foreach($table_rows as $tr) { // foreach row
$row = $tr->childNodes;
if($row->item(0)->tagName != 'tblhead') { // avoid headers
    $sql = "INSERT INTO `Dadoo`(title,liveprice,changing,lowest,topest,time) VALUES ('" . trim($row->item(0)->nodeValue) . "','" . trim($row->item(2)->nodeValue) . "','" . trim($row->item(4)->nodeValue) . "','" . trim($row->item(6)->nodeValue) . "','" . trim($row->item(8)->nodeValue) . "','" . trim($row->item(10)->nodeValue) . "')");
    mysql_query($sql);
}

}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.