• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

dateisalat in mysql einpflegen

unendlich

Neues Mitglied
Hoi, nachdem ich etliche Stunden vergeblich am tüfteln war, bleibt mir nun der letzte Ausweg. Also es geht sich um folgendes:

Code:
- <data>
- <sector coords="1">
  <planet id="10317" name="" class="10" coords="105" /> 
  <planet id="10318" name="[01]-[Suffering]" class="3" coords="111" user_id="2649" user_name="Gnadolin" alli_id="1120" alli_tag="[-F-]" /> 
  <planet id="10319" name="" class="1" coords="117" /> 
  <planet id="10320" name="REWE" class="18" coords="130" user_id="469" user_name="Moe" alli_id="1120" alli_tag="[-F-]" /> 
  <planet id="10321" name="SUBWAY" class="16" coords="127" user_id="469" user_name="Moe" alli_id="1120" alli_tag="[-F-]" /> 
  </sector>
- <sector coords="2">
  <planet id="10504" name="Warbase I" class="7" coords="231" user_id="403" user_name="Epinephrinjunky" alli_id="1148" alli_tag="-DT-" /> 
  <planet id="10505" name="IchHoffeEsTuTWeh Basis" class="25" coords="201" user_id="8511" user_name="IchHoffeEsTuTWeh" /> 
  <planet id="10506" name="" class="28" coords="212" /> 
  <planet id="10507" name="00-02-17" class="16" coords="217" user_id="7739" user_name="Karlchen" alli_id="1115" alli_tag="-(TTF)-" /> 
  <planet id="10508" name="" class="20" coords="207" /> 
  </sector>
- <sector coords="3">
  <planet id="10693" name="" class="10" coords="315" /> 
  <planet id="10694" name="Warbase H" class="9" coords="327" user_id="403" user_name="Epinephrinjunky" alli_id="1148" alli_tag="-DT-" /> 
  <planet id="10695" name="" class="1" coords="313" /> 
  <planet id="10696" name="" class="20" coords="306" /> 
  <planet id="10697" name="AC Hokus" class="4" coords="302" user_id="5955" user_name="Teufelsengel" alli_id="1115" alli_tag="-(TTF)-" /> 
  </sector>
- <sector coords="4">
  <planet id="10895" name="Menzoberranzan" class="2" coords="408" /> 
  <planet id="10896" name="Bita IV" class="5" coords="406" user_id="5240" user_name="RoccoStorm" alli_id="836" alli_tag="BdF" /> 
  <planet id="10897" name="00-04-18" class="8" coords="418" user_id="3155" user_name="DarthVader" alli_id="275" alli_tag="-BG-" /> 
  <planet id="10898" name="" class="23" coords="426" /> 
  <planet id="10899" name="" class="12" coords="424" /> 
  </sector>
  </data>

Das will ich sauber inne sql db einarbeiten. Meine Versuche, es als .xml zu speichern klappt auch halbwegs aber ich bleib immer hängen.
In Kurzform:

PHP:
<?php
$xml = simplexml_load_file("uni.xml");
#var_dump($xml->universe->sector->planet)
print_r($xml->universe->sector->planet)
?>

Allerdings bekomm ich den Rest nicht gefasst mit ->ID oder ->Name etc.
Mein Ziel ist später eine Art Datenbank zu machen um verschiedene Daten anzeigen zulassen, aber erstmal muss ich das ganze in die DB bekommen :(
Meine versuche als .txt schlugen auch fehl, da es nur eine fortlaufende Zeile ist und ich mit den Parametern nicht die Sache greifen kann die ich will.

Kann mir jemand auf die Sprünge helfen? Ich hab son etliche Hilfe Seiten nachgeschaut, aber mir fehlt da immer was :S

Danke schonmal im Vorraus :)
 
hat geklappt, nun stehe ich vor dem nächsten problem >.<

PHP:
<?php
include 'aktuell.php';
$xml = simplexml_load_file('uni.xml');
$tabs = array("id","name","class","coords","user_id","user_name","alli_id","alli_tag");


$q_cnt = count($xml->universe->sector); 
 for($j = 0; $j < $q_cnt; $j++) 
 		{ 
	 		$planet = $xml->universe->sector[$j]->planet->attributes();
			$p_cnt = count($xml->universe->sector->planet); 
 			for($i = 0; $i < $p_cnt; $i++) 
 		{ 
 				$planet = $xml->universe->sector[$j]->planet[$i]->attributes();
 		 		foreach($planet as $key => $value) 
				{
				$array 		=	array ($key,$value);
						if (in_array($tabs[3], $array)) {
						if (strlen($array[1]) == 3) {
						$new_string = substr_replace($array[1], '00-0', 0, 0);
						$last_string = substr_replace($new_string, '-', -2, -2);
						} elseif (strlen($array[1]) == 4) {
						$new_string = substr_replace($array[1], '00-', 0, 0);
						$last_string = substr_replace($new_string, '-', -2, -2);
						} elseif (strlen($array[1]) == 5) {
						$new_string = substr_replace($array[1], '0', 0, 0);
						$new_string2 = substr_replace($new_string, '-', -4, -4);
						$last_string = substr_replace($new_string2, '-', -2, -2);
						} elseif (strlen($array[1]) == 6) {
						$new_string = substr_replace($array[1], '-', -4, -4);
						$last_string = substr_replace($new_string, '-', -2, -2);
						}												
						$sql_string_coords = $last_string;
						#echo "<pre>",$array[0],': ',$last_string;		//Coords
						} if (in_array($tabs[2], $array)) {
						if ($array[1] <= 2) {
						$last_string2 = "A";
						} elseif ($array[1] <= 9) {
						$last_string2 = "B";
						} elseif ($array[1] <= 12) {
						$last_string2 = "C";
						} elseif ($array[1] <= 18) {
						$last_string2 = "D";
						} elseif ($array[1] <= 24) {
						$last_string2 = "E";
						} elseif ($array[1] <= 31) {
						$last_string2 = "F";
						}
						$sql_string_class = $last_string2;
						#echo "<pre>",$array[0],': ',$last_string2;		//Class
						} if (in_array('id', $array)) {
						$sql_string_pid = $array[1];
						#echo "<pre>",$array[0],': ',$array[1];			//Planet_ID	
						} if (in_array('name', $array)) {
						$sql_string_name = $array[1];
						#echo "<pre>",$array[0],': ',$array[1];   		//Name
						} if (in_array('user_id', $array)) {
						$sql_string_userid = $array[1];
						#echo "<pre>",$array[0],': ',$array[1];			//User_ID   
						} if (in_array('user_name', $array)) {
						$sql_string_usernick = $array[1];
						#echo "<pre>",$array[0],': ',$array[1];			//User_Name
						} if (in_array('alli_id', $array)) {
						$sql_string_alliid = $array[1];						
						#echo "<pre>",$array[0],': ',$array[1];			//Alli_ID
						} if (in_array('alli_tag', $array)) {
						$sql_string_allitag = $array[1];
						#echo "<pre>",$array[0],': ',$array[1];   		//Alli_TAG
						}
							$sql = "INSERT INTO `evil`.`liste` (
							`ID`, 
							`Planet_ID`, 
							`Name`, 
							`Class`, 
							`Coords`, 
							`User_ID`, 
							`User_Name`, 
							`Alli_ID`, 
							`Alli_Tag`, 
							`Datum`) 
							VALUES (
							NULL, 
							'$sql_string_pid', 
							'$sql_string_name', 
							'$sql_string_class', 
							'$sql_string_coords', 
							'$sql_string_userid', 
							'$sql_string_usernick', 
							'$sql_string_alliid', 
							'$sql_string_allitag', 
							CURRENT_TIMESTAMP);";		
							$add_sql = mysql_query($sql) or die("Anfrage fehlgeschlagen: " . mysql_error());
							
				} 
 		}	
} 
?>



So siehts inner DB aus. (Zwischen den if schleifen gibt er die werte richtig aus, aber da kann ich die sql anfrage nich einsetzen) bräuchte noch nen Tipp :roll:

 
Zurück
Oben