0

Hey Guys I am writing a application in PHP. One feature is that the admin can create a question for a test in the application. I want to use the users input to create an xml file and save the xml file in mysql database for later use. This is what i have so far


This is the php code that writes the xml

<?php 
  $questions = array(); 
  $questions [] = array( 
  'text' => 'question info', 
  'varx' => '34', 
  'vary' => '$10000' 
  ); 
  $questions [] = array( 
  'text' => 'question info', 
  'varx' => '20', 
  'vary' => "2000" 
  ); 
   
  $doc = new DOMDocument(); 
  $doc->formatOutput = true; 
   
  $r = $doc->createElement( "questions" ); 
  $doc->appendChild( $r ); 
   
  foreach( $questions as $question ) 
  { 
  $b = $doc->createElement( "question" ); 
   
  
  $text = $doc->createElement( "text" ); 
  $text->appendChild( 
  $doc->createTextNode( $question['text'] ) 
  ); 
  $b->appendChild( $text ); 
  


  
  $varx = $doc->createElement( "varx" ); 
  $varx->appendChild( 
  $doc->createTextNode( $question['varx'] ) 
  ); 
  $b->appendChild( $varx ); 
  
  
	$lrange1 = $doc->createElement( "lrange1" ); 
  $lrange1->appendChild( 
  $doc->createTextNode( $question['lrange1'] ) 
  ); 
  $varx->appendChild( $lrange1 );

  
  $vary = $doc->createElement( "vary" ); 
  $vary->appendChild( 
  $doc->createTextNode( $question['vary'] ) 
  ); 
  $b->appendChild( $vary ); 



  
  $r->appendChild( $b ); 
  } 
   
  echo $doc->saveXML(); 
  $doc->save("testquestions.xml") 
  ?>

this is the output in xml

<?xml version="1.0"?>
<questions>
  <question>
    <text>question info</text>
    <varx>34<lrange1></lrange1></varx>
    <vary>$10000</vary>
  </question>
  <question>
    <text>question info</text>
    <varx>20<lrange1></lrange1></varx>
    <vary>2000</vary>
  </question>
</questions>

i want the out put to resemble this

<?xml version="1.0" encoding="ISO-8859-1"?>
<question>
       <text>You have a [x] Click-Through-Rate, The percentage of people that click on an ad they are presented with, in position 1 in Googles adspace. You have a [y] Click-Through-Rate in position 2.
			Based on these two numbers, what is your average CTR if your average position is the [z]?
		</text>
       <varx>
		   <lrange1>2</lrange1>
		   <lrange2>7</lrange2>
			<urange1>11</urange1>
		   <urange2>15</urange2>
	   </varx>
	   
	    <vary>
		   <lrange1>20</lrange1>
		   <lrange2>25</lrange2>
			<urange1>27</urange1>
		   <urange2>32</urange2>
	   </vary>
	   
	   <varz>
		   <lrange1>10</lrange1>
		   <lrange2>12</lrange2>
			<urange1>17</urange1>
		   <urange2>22</urange2>
	   </varz>
		<formula>
			x -((x-y) * (z-1))
		</formula>
   </question>

my goal here is to have my app get questions from a data base and randomize the variable in the question and give the ability of the admin to create new questions


Any help is greatly appreciated!!

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by jaycastr
0

my first issue is that i cant get a value into <lrange1></lrange1>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.