473,394 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to write php code to get xml dynamic page?

Hi all
need to write php code to get xml dynamic page. i have attached an out of the code can any one help to solve it out?
i have created database name called 'new' with 3 tables first is 'games' with field gid as primary key, gname primary key gid, second table is 'levels' with the field lvalue as primary key , gid as foreign key and the third table is display_items with did as primary key , dname meaning , position , shape , lid as foreign key.
please see the attachment file and help me to create PHP code to get this output.
Thanks
Attached Files
File Type: txt xmlfile1.txt (5.9 KB, 481 views)
Feb 19 '13 #1
3 1858
Rabbit
12,516 Expert Mod 8TB
This is not a code writing service but if you post the code you've tried along with a description of the problem you're having with it, we can help guide you to a solution.

Also, as a rule of thumb, we don't download attachments from strangers. Please post all pertinent information in the thread itself. If it is code or XML, use code tags when doing so.
Feb 19 '13 #2
The following is php code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $xml = new SimpleXMLElement('<xml/>');
  4.  
  5. $conn=mysql_connect('localhost','root','password') or die(mysql_error());
  6.  
  7. mysql_query("SET NAMES 'utf8'", $conn); 
  8. mysql_select_db('new') or die (mysql_error());
  9.  
  10.  
  11. $games = $xml->addChild('games');
  12. $game = $games->addChild('game');
  13.  
  14. $query1 = mysql_query("SELECT game_id , game_name FROM games"); 
  15. $query2 =mysql_query("SELECT * FROM levels WHERE game_id = " . $row['game_id'] .");
  16. $query3 =mysql_query("SELECT * FROM Letter_info WHERE level_value = " . $sql2['level_value'] .");
  17.  
  18.     if($query_run1 = mysql_query($query1)){    
  19.             if ($query_run2 = mysql_query($query2)){
  20.                 if ($query_run3 = mysql_query($query3)){    
  21.                    $query_row1 = mysql_fetch_assoc($query_run1);
  22.                    $game_id = $game->addChild('gameid', "$query_row1[game_id]");        
  23.                     $game_name = $game->addChild('gamename' , "$query_row1[game_name]");
  24.                     $levels = $game->addChild('levels');        
  25.                         $query_row2 = mysql_fetch_assoc($query_run2);
  26.  
  27.  
  28.  
  29.                             $level = $levels->addChild('level');
  30.                             $level_value = $level->addChild('levelvalue'."$query_row2[level_value]");
  31.  
  32.  
  33.                             while($query_row3 = mysql_fetch_assoc($query_run3)){
  34.  
  35.  
  36.  
  37.                             $displayitem = $level->addChild('displayitems');
  38.                             $letter_id = $displayitem->addChild('displayid' , "$query_row3[letter_id]");    
  39.                                 $letter_name = $displayitem->addChild('display_name' , "$query_row3[letter_name]");
  40.                                 $meaning = $displayitem->addChild('Meaning' , "$query_row3[meaning]");
  41.                                 $position = $displayitem->addChild('Position' , "$query_row3[position]");    
  42.                                 $shapes = $displayitem->addChild('shapes');
  43.                                 $shape = $shapes->addChild('shape', "$query_row3[shape1]");
  44.                         }
  45.  
  46.  
  47.  
  48.                     }    
  49.             }
  50.         }            
  51.  
  52. Header('Content-type: text/xml');
  53.  
  54. print($xml->asXML());
  55. ?>
NEED TO GET XML DYNAMIC PAGE AS OUT PUT:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <games>
  3.     <game>
  4.         <gameId>1</gameId>
  5.         <gameName>Word Match</gameName>
  6.         <levels>
  7.             <level value="0">
  8.                 <display-item>
  9.                     <displayId></displayId>
  10.                     <displayName>ا</displayName>
  11.                     <meaning></meaning>
  12.                     <position>1</position>
  13.                     <shapes>
  14.                         <shape></shape>
  15.                     </shapes>
  16.                 </display-item>
  17.                 <display-item>
  18.                     <displayId>1</displayId>
  19.                     <displayName>A</displayName>
  20.                     <meaning></meaning>
  21.                     <position>2</position>
  22.                     <shapes>
  23.                         <shape></shape>
  24.                     </shapes>
  25.                 </display-item>
  26.                 <display-item>
  27.                     <displayId>1</displayId>
  28.                     <displayName>B</displayName>
  29.                     <meaning></meaning>
  30.                     <position>3</position>
  31.                     <shapes>
  32.                         <shape></shape>
  33.                     </shapes>
  34.                 </display-item>
  35.                 <display-item>
  36.                     <displayId>1</displayId>
  37.                     <displayName>C</displayName>
  38.                     <meaning></meaning>
  39.                     <position>4</position>
  40.                     <shapes>
  41.                         <shape></shape>
  42.                     </shapes>
  43.                 </display-item>
  44.                 <display-item>
  45.                     <displayId>1</displayId>
  46.                     <displayName>D</displayName>
  47.                     <meaning></meaning>
  48.                     <position>5</position>
  49.                     <shapes>
  50.                         <shape></shape>
  51.                     </shapes>
  52.                 </display-item>
  53.                 <display-item>
  54.                     <displayId>1</displayId>
  55.                     <displayName>E</displayName>
  56.                     <meaning></meaning>
  57.                     <position>6</position>
  58.                     <shapes>
  59.                         <shape></shape>
  60.                     </shapes>
  61.                 </display-item>
  62.                 <display-item>
  63.                     <displayId>1</displayId>
  64.                     <displayName>F</displayName>
  65.                     <meaning></meaning>
  66.                     <position>7</position>
  67.                     <shapes>
  68.                         <shape></shape>
  69.                     </shapes>
  70.                 </display-item>
  71.                 <display-item>
  72.                     <displayId>1</displayId>
  73.                     <displayName>G</displayName>
  74.                     <meaning></meaning>
  75.                     <position>8</position>
  76.                     <shapes>
  77.                         <shape></shape>
  78.                     </shapes>
  79.                 </display-item>
  80.                 <display-item>
  81.                     <displayId>1</displayId>
  82.                     <displayName>H</displayName>
  83.                     <meaning></meaning>
  84.                     <position>9</position>
  85.                     <shapes>
  86.                         <shape></shape>
  87.                     </shapes>
  88.                 </display-item>
  89.                 <display-item>
  90.                     <displayId>1</displayId>
  91.                     <displayName>I</displayName>
  92.                     <meaning></meaning>
  93.                     <position>10</position>
  94.                     <shapes>
  95.                         <shape></shape>
  96.                     </shapes>
  97.                 </display-item>
  98.                 <display-item>
  99.                     <displayId>1</displayId>
  100.                     <displayName>J</displayName>
  101.                     <meaning></meaning>
  102.                     <position>11</position>
  103.                     <shapes>
  104.                         <shape></shape>
  105.                     </shapes>
  106.                 </display-item>
  107.                 <display-item>
  108.                     <displayId>1</displayId>
  109.                     <displayName>K</displayName>
  110.                     <meaning></meaning>
  111.                     <position>12</position>
  112.                     <shapes>
  113.                         <shape></shape>
  114.                     </shapes>
  115.                 </display-item>
  116.                 <display-item>
  117.                     <displayId>1</displayId>
  118.                     <displayName>L</displayName>
  119.                     <meaning></meaning>
  120.                     <position>13</position>
  121.                     <shapes>
  122.                         <shape></shape>
  123.                     </shapes>
  124.                 </display-item>
  125.                 <display-item>
  126.                     <displayId>1</displayId>
  127.                     <displayName>M</displayName>
  128.                     <meaning></meaning>
  129.                     <position>14</position>
  130.                     <shapes>
  131.                         <shape></shape>
  132.                     </shapes>
  133.                 </display-item>
  134.                 <display-item>
  135.                     <displayId>1</displayId>
  136.                     <displayName>N</displayName>
  137.                     <meaning></meaning>
  138.                     <position>15</position>
  139.                     <shapes>
  140.                         <shape></shape>
  141.                     </shapes>
  142.                 </display-item>
  143.                 <display-item>
  144.                     <displayId>1</displayId>
  145.                     <displayName>O</displayName>
  146.                     <meaning></meaning>
  147.                     <position>16</position>
  148.                     <shapes>
  149.                         <shape></shape>
  150.                     </shapes>
  151.                 </display-item>
  152.                 <display-item>
  153.                     <displayId>1</displayId>
  154.                     <displayName>P</displayName>
  155.                     <meaning></meaning>
  156.                     <position>17</position>
  157.                     <shapes>
  158.                         <shape></shape>
  159.                     </shapes>
  160.                 </display-item>
  161.                 <display-item>
  162.                     <displayId>1</displayId>
  163.                     <displayName>Q</displayName>
  164.                     <meaning></meaning>
  165.                     <position>18</position>
  166.                     <shapes>
  167.                         <shape></shape>
  168.                     </shapes>
  169.                 </display-item>
  170.                 <display-item>
  171.                     <displayId>1</displayId>
  172.                     <displayName>R</displayName>
  173.                     <meaning></meaning>
  174.                     <position>19</position>
  175.                     <shapes>
  176.                         <shape></shape>
  177.                     </shapes>
  178.                 </display-item>
  179.                 <display-item>
  180.                     <displayId>1</displayId>
  181.                     <displayName>S</displayName>
  182.                     <meaning></meaning>
  183.                     <position>20</position>
  184.                     <shapes>
  185.                         <shape></shape>
  186.                     </shapes>
  187.                 </display-item>
  188.                 <display-item>
  189.                     <displayId>1</displayId>
  190.                     <displayName>T</displayName>
  191.                     <meaning></meaning>
  192.                     <position>21</position>
  193.                     <shapes>
  194.                         <shape></shape>
  195.                     </shapes>
  196.                 </display-item>
  197.                 <display-item>
  198.                     <displayId>1</displayId>
  199.                     <displayName>U</displayName>
  200.                     <meaning></meaning>
  201.                     <position>22</position>
  202.                     <shapes>
  203.                         <shape></shape>
  204.                     </shapes>
  205.                 </display-item>
  206.                 <display-item>
  207.                     <displayId>1</displayId>
  208.                     <displayName>V</displayName>
  209.                     <meaning></meaning>
  210.                     <position>23</position>
  211.                     <shapes>
  212.                         <shape></shape>
  213.                     </shapes>
  214.                 </display-item>
  215.                 <display-item>
  216.                     <displayId>1</displayId>
  217.                     <displayName>W</displayName>
  218.                     <meaning></meaning>
  219.                     <position>24</position>
  220.                     <shapes>
  221.                         <shape></shape>
  222.                     </shapes>
  223.                 </display-item>
  224.                 <display-item>
  225.                     <displayId>1</displayId>
  226.                     <displayName>X</displayName>
  227.                     <meaning></meaning>
  228.                     <position>25</position>
  229.                     <shapes>
  230.                         <shape></shape>
  231.                     </shapes>
  232.                 </display-item>
  233.                 <display-item>
  234.                     <displayId>1</displayId>
  235.                     <displayName>Y</displayName>
  236.                     <meaning></meaning>
  237.                     <position>26</position>
  238.                     <shapes>
  239.                         <shape></shape>
  240.                     </shapes>
  241.                 </display-item>
  242.                 <display-item>
  243.                     <displayId>1</displayId>
  244.                     <displayName>Z</displayName>
  245.                     <meaning></meaning>
  246.                     <position>27</position>
  247.                     <shapes>
  248.                         <shape></shape>
  249.                     </shapes>
  250.                 </display-item>
  251.             </level>
  252.         </levels>
  253.     </game>
  254. </games>

HELP ME SOLVE THIS WHERE I GET THE PROBLEM
Feb 28 '13 #3
Rabbit
12,516 Expert Mod 8TB
You haven't said what the problem is. Are you getting error codes? What are they? Are you getting incorrect output? What is the incorrect output?
Feb 28 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mark | last post by:
I'm interested in displaying a dynamic page title, rather than the static html <title>My Page</title>. In a previous posting, I had seen a suggestion of making the title into a server control...
1
by: Jignesh Desai | last post by:
There are essentially two ways that you can write code for an ASP.NET application. Inline code Style --------------------------------------------------------------- <html> <script...
3
by: vodafone | last post by:
Hy all I've a little problem. I need to write a dynamic page that render control according to validation status return from previous control validation status. To be clear, I've page that...
0
by: Learner | last post by:
Hello, We use Master Pages in our website and need a page to be created dynamically. I am not sure where I am missing but I don't see any error and the controls on the page either! Here is my...
4
by: Chris | last post by:
Can anyone recommend how to do a screen scrape from a dynamic page and save it to a text file? Regards, Chris.
4
by: Ed Jay | last post by:
I generate a DHTML page (a medical report) with dynamically generated text based on user input (answers to questions). The page length changes dynamically. I desire that when the page is printed...
1
by: florencepushpa | last post by:
hi, i need to create a staic and dynamic page in html.pls give the code. Thank u Pushpa
5
by: ycquak | last post by:
Hi, Currently I need to read contents from a dynamic page, which goes something like: http://servername/filename.jsp?arg1=a&arg2=b The content is not static, neither is there a file for me to...
1
by: braich | last post by:
Hi All I am new to PHP and have been reading few basic books on PHP. I am trying to create a dynamic page based on the keyword in the url. Let’s say I have...
2
by: ganesh22 | last post by:
Hi, How to write code in page load to display that window size like popup? ex: Here i writen the code in OnClientClick event now i want in page load javascript:window.open('Default4.aspx?a='...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.