Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

XML mit php in Datenbank schreiben

Empfohlene Antworten

Veröffentlicht

Hallo zusammen!

Ich hab schon so viel gegoogelt. Doch irgendwie hilft mir das alles nicht wirklich weiter.

ich hab eine XML-Datei:

<?xml version="1.0"?>

<!-- XML Datei fuer das Uebernahmeprotokoll -->

<auto>

<kennzeichen>pa-xx 123</kennzeichen>

<hersteller>Audi</hersteller>

<type>A3</type>

<modell>2.0 TDI Quattro</modell>

<sondermodell>S-Line</sondermodell>

</auto>

Die anzahl der Elemente ist aber variabel.. :-(

Ich will mir aus dieser Datei einfach nur eine SQL-String zusammenbaun. Die elementnamen, haben den gleichen namen, wie die namen in der Datenbank. Kennzeichen heißt in der datenbank auch kennzeichen. Der Text zwischen <kennzeichen> und </kennzeichen> soll in das Feld der Datenbank kennzeichen geschrieben werden. kann doch nicht so schwer sein. :-( aber ich brings nicht hin.. hat jemand von euch vielleicht etwas ?

Danke !

Also ich habe mal in meinem alten Code gewühlt:

$bulletin = simplexml_load_file('http://localhost/_crons/bulletin2_output.xml');
$j = 0;
//Zähler, der zum Einlesen genutzt wird
$bid = array();
$title = array();
$rubricID = array();
$rubric_name = array();
$offer = array();
$startdate = array();
$description = array();
$state = array();

foreach ($bulletin->posts as $posts) {
$bid[$j] = $posts->BID;
$title[$j] = utf8_decode($posts->title);
$description[$j] = utf8_decode($posts->description);
//echo $description[$j];
$rubricID[$j] = $posts->RID;
//$rubric_name[$j] = $posts->rubric_name;
$offer[$j] = $posts->offer;
$startdate[$j] = $posts->startdate;
$lastchange[$j] = $posts->lastchange;
$state[$j] = $posts->state;
$j++;
}[/PHP]

Hier habe ich den Inhalt des XML-Files aus in einen Array gespeichert...

[PHP]for ($i = 0; $i < $j; $i++) {
//hier noch nicht ganz fertig...
if($bid[$i] <= $last[0]){
$update = "UPDATE `bulletin2` SET `title` = '$title[$i]',
`description` = '$description[$i]',
`rubric_ID` = $rubricID[$i],
`offer` = '$offer[$i]',

`startdate` = '$startdate[$i]',
`lastchange` = '$lastchange[$i]',
`state` = '$state[$i]'
WHERE `BID` = $bid[$i]";
//$update = "UPDATE `bulletin2` SET `title` = `$title[$i]` where `BID` = $bid[$i]";

//echo $update;
$stmt = $mysqli->prepare($update);

$stmt->execute();
}
else{
$stmt = $mysqli->prepare("INSERT INTO bulletin2 ( `BID` , `title` , `description` , `rubric_id` , `offer` , `startdate` , `lastchange`,`state` )values ($bid[$i],'$title[$i]','$description[$i]',$rubricID[$i],'$offer[$i]','$startdate[$i]','$lastchange[$i]', '$state[$i]')");
$stmt->execute();

//echo "INSERT INTO bulletin2 ( `BID` , `title` , `description` , `rubic_id` , `rubic_name` , `offer` , `startdate` , `lastchange`,`state` )values ($bid[$i],'$title[$i]','$description[$i]',$rubricID[$i],'$rubric_name[$i]','$offer[$i]','$startdate[$i]','$lastchange[$i]', $state[$i]')";
// echo $lastchange[$i];
}
}

und hier in die DB gespeichert...

Naja, vielleicht hilft es ja weiter...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.