Answer the question
In order to leave comments, you need to log in
How to form xml using sql?
I have an xml document like this:
<HeadNode>
<information>
<lastName>Иванов</lastName>
<firstName>Иван</firstName>
<birthDate>1900-01-01</birthDate>
<gender>M</gender>
</information>
<documents>
<document>
<type>Passport</type>
<number>123456</number>
<issueDate>2000-01-01</issueDate>
</document>
</documents>
<contacts>
<contact>
<type>Mphone</type>
<phoneNumber>1234567890</phoneNumber>
</contact>
<contact>
<type>Hphone</type>
<phoneNumber>0987654321</phoneNumber>
<region>
<code>Odessa_region</code>
</region>
<city>
<code>Odessa</code>
</city>
</contact>
<contact>
<type>Work</type>
<region>
<code>Odessa_region</code>
</region>
<city>
<code>Odessa</code>
</city>
</contact>
</contacts>
</HeadNode>
Answer the question
In order to leave comments, you need to log in
$dbc = mysqli_connect($host, $username, $password, $database);
$data = mysqli_query($dbc, "SELECT * FROM users");
while ($row = mysqli_fetch_array($data)) {
$res .= "<HeadNode>
<information>
<lastName>".$row['name']."</lastName>
<firstName>".$row['lastname']."</firstName>
<birthDate>".$row['bday']."</birthDate>
<gender>".$row['gender']."</gender>
</information>
<documents>
<document>
<type>Passport</type>
<number>".$row['number']."</number>
<issueDate>".$row['date']."</issueDate>
</document>
</documents>
<contacts>
<contact>
<type>Mphone</type>
<phoneNumber>".$row['mphone']."</phoneNumber>
</contact>
<contact>
<type>Hphone</type>
<phoneNumber>".$row['hphone']."</phoneNumber>
<region>
<code>".$row['region']."</code>
</region>
<city>
<code>".$row['city']."</code>
</city>
</contact>
<contact>
<type>Work</type>
<region>
<code>".$row['region']."</code>
</region>
<city>
<code>".$row['city']."</code>
</city>
</contact>
</contacts>
</HeadNode>";
}
mysqli_close($dbc);
echo $res;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question