-
-
Save anonymous/179601fc6723fb942741 to your computer and use it in GitHub Desktop.
Getting back ma favorites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!$dbconnect = mysql_connect('localhost', '.', '.')) | |
{ | |
echo "Connection failed to the host 'localhost'."; | |
exit; | |
} // if | |
if (!mysql_select_db('.')) { | |
echo "Cannot connect to database '.'"; | |
exit; | |
} // if | |
mysql_set_charset('utf8', $dbconnect); | |
$table_id = 'Forever'; | |
$table_id2 = 'BenutzerFavoriten'; | |
$name = mysql_real_escape_string("foobar"); | |
$query = "SELECT Favoriten FROM $table_id2 WHERE Name = $name"; | |
$favoritenstring = mysql_fetch_assoc(mysql_query($query)); | |
$string = stripslashes($favoritenstring['Favoriten']); | |
$query = "SELECT Name,Beitrag,Bild,satzid FROM $table_id WHERE satzid in " .$string; | |
$dbresult = mysql_query($query, $dbconnect); | |
// create a new XML document | |
$doc = new DomDocument('1.0'); | |
// create root node | |
$root = $doc->createElement('root'); | |
$root = $doc->appendChild($root); | |
// process one row at a time | |
while($row = mysql_fetch_assoc($dbresult)) { | |
// add node for each row | |
$occ = $doc->createElement($table_id); | |
$occ = $root->insertBefore($occ, $root->firstChild); | |
// add a child node for each field | |
foreach ($row as $fieldname => $fieldvalue) { | |
$child = $doc->createElement($fieldname); | |
$child = $occ->appendChild($child); | |
$value = $doc->createTextNode($fieldvalue); | |
$value = $child->appendChild($value); | |
} // foreach | |
} // while | |
// get completed xml document | |
$xml_string = $doc->saveXML(); | |
$doc->save("Favoriten+$name.xml") | |
//echo $xml_string; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment