note 107749 rejected from function.array-unique by danbrown

From: Date: Thu, 10 May 2012 18:31:45 +0000
Subject: note 107749 rejected from function.array-unique by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187772@lists.php.net to get a copy of this message
Note Submitter: a dot goergens at web dot de ---- Hi Guys I got a multidimensional array coming from a database and automatically wanted to push that into a mysql database with all the data and also if possible with realations if the array gets nested. I get the data by a Game via API (ReferenceOutput: http://wiki.eve-id.net/APIv2_Char_KillLog_XML) . I am using the Pheal lib which can be found here to access the api and which works fine. https://github.com/ppetermann/pheal What i want to have is a complete Array2MYSQL insert and create so the data when it comes from the api is always stored in correct manner Anybody can help me? here are my two functions I tried to use Rawdata : from the Lib ->http://www.sendspace.com/file/r2cekj Rawdata from my Array -> http://www.sendspace.com/file/zg1a32 $table= "corpkills"; $tcounter = "1" -> in my example function array2mysql($array,$table,$tcounter) { $values = array(); $fields = array(); $wert = array(); $tcounter = $tcounter+1; foreach($array as $field =>$value) { if(is_array($value)) { $fields[] = "" . $field . ""; $values[] = "'" . $value . "'"; $wert = array2mysql($value,$table,$tcounter); } $fields[] = "" . $field . ""; $values[] = "'" . $value . "'"; } $field_list = join(',', $fields); $value_list = join(', ', $values); $query = $wert . "INSERT INTO " . $table . $tcounter. " (" . $field_list . ") VALUES (" . $value_list . ");"; return $query ; } function array2mysql_create($array,$table,$tcounter) { $values = array(); $fields = array(); $wert = array(); $tcounter= $tcounter+ 1; foreach($array as $field =>$value) { if(is_array($value)) { $fields[] = "" . $field . "varchar (255) NOT NULL"; $wert = array2mysql_create($value,$table,$tcounter); } else { $fields[] = "" . $field . "varchar (255) NOT NULL"; } } $field_list = join(',', $fields); $value_list = join(', ', $values); $query = $wert . "CREATE TABLE " . $table . $tcounter. " (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id)," . $field_list . ");"; return $query ; }

« previous php.notes (#187772) next »