note 107749 added to function.array-unique

From: Date: Thu, 01 Mar 2012 17:49:49 +0000
Subject: note 107749 added to function.array-unique
Groups: php.notes 
Request: Send a blank email to php-notes+get-186450@lists.php.net to get a copy of this message
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 ; } ---- Server IP: 69.147.83.197 Probable Submitter: 84.131.69.72 ---- Manual Page -- http://www.php.net/manual/en/function.array-unique.php Edit -- https://master.php.net/note/edit/107749 Del: integrated -- https://master.php.net/note/delete/107749/integrated Del: useless -- https://master.php.net/note/delete/107749/useless Del: bad code -- https://master.php.net/note/delete/107749/bad+code Del: spam -- https://master.php.net/note/delete/107749/spam Del: non-english -- https://master.php.net/note/delete/107749/non-english Del: in docs -- https://master.php.net/note/delete/107749/in+docs Del: other reasons-- https://master.php.net/note/delete/107749 Reject -- https://master.php.net/note/reject/107749 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186450) next »