Note that there are some explanatory texts on larger screens.

plurals
  1. POphp and mysql to xml
    primarykey
    data
    text
    <p>i have 2 tables, first one which stores restaurant info and second stores dishes served in each. They are linked using res_id. </p> <p>1) info_main [id, res_id, res_name,res_pc] 2) dishes [id,dishName,price,res_id(Foreign key)]</p> <p>My SQL query is </p> <pre><code>$query = "SELECT * FROM info_main LEFT JOIN dishes ON info_main.res_id = dishes.res_id"; </code></pre> <p>I am inserting the results from the query into an xml file which works fine. Below is the code:</p> <pre><code> $query = "SELECT * FROM info_main LEFT JOIN dishes ON info_main.res_id = dishes.res_id"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); echo '&lt;markers&gt;'; // Iterate through the rows, printing XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE echo '&lt;marker&gt; '; echo '&lt;detail1&gt;'; echo '&lt;resdetails '; echo 'name="' . parseToXML($row['res_name']) . '" '; echo 'id="' . parseToXML($row['res_ID']) . '" '; echo 'pc="' . parseToXML($row['res_pc'] ). '" '; echo '/&gt;'; echo '&lt;dishdetails '; echo 'name="' . parseToXML($row['dishName']) . '" '; echo 'price="' . parseToXML($row['price']) . '" '; echo '/&gt;'; echo '&lt;/detail1&gt;'; echo '&lt;/marker&gt;'; } </code></pre> <p>This work fine however if a restaurant has 3 dishes in the database, then xml create 3 nodes: Something like this:</p> <p><img src="https://i.stack.imgur.com/etb8n.png" alt="xml file putput"></p> <p>I want the xml structure like </p> <pre><code>&lt;detail1&gt; &lt;resdetails name="spoted dog" id="xyz" pc="xyz"/&gt; &lt;dishdetails name="bean burger" price="1" /&gt; &lt;dishdetails name="cheese and tomato panini" price="3" /&gt; &lt;dishdetails name="veg salad" price="2" /&gt; &lt;/details1&gt; </code></pre> <p>I cant figure out a way how to achieve the above stated xml structure. Your help is greatly appreciated. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload