Ver Mensaje Individual
  #8 (permalink)  
Antiguo 22/11/2012, 15:37
nicomonjes
 
Fecha de Ingreso: abril-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 33
Antigüedad: 15 años
Puntos: 1
Respuesta: Incorporar include dentro de xml con php

Creo que comenzó a funcionarme porque ya hace el bucle pero creo que no estoy enviando bien las variables al array porque me devuelve todos los datos vacíos, solo me pone la imagen bien, o sea que todo lo que tiene que traer desde el array y lo que el array hace en la función no vuelve.. será porque todo tiene que estar dentro del print? o estoy haciendo mal las llamadas

<question>
<text>Pregunta</text>
[
<img src="profile/1353094808.jpg" alt="Profile"/>
]
<option>
<text/>
<score/>
</option>
<option>
<text/>
<score/>
</option>
<option>
<text/>
<score/>
</option>
</question>


Código PHP:
Ver original
  1. <?php
  2. header("Content-type: text/xml");
  3. include("../../../ws/conexion.php");
  4.  
  5. function getNombre($sexo, $link) {
  6.     $sql = "SELECT usuarios.* FROM usuarios WHERE usuarios.sexo = '$sexo' order by RAND() limit 1";
  7.     $r = mysql_query($sql, $link); //ATENCIÓN! Función deprecada ;)
  8.     $arr = mysql_fetch_array($r);
  9.     return $arr['nombre'];
  10. }  
  11.  
  12.  
  13.  
  14.  
  15.     $result=mysql_query("SELECT usuarios.* FROM usuarios order by RAND() limit 100",$link);
  16. echo '<quizzes>';
  17. echo '  <quiz>';
  18. echo '    <title>Quien es Quien?</title>';
  19. echo '    <grading>';
  20. echo '      <range start="0" end="100">';
  21. echo '        <grade>F</grade>';
  22. echo '        <rank>Rank</rank>';
  23. echo '      </range>';
  24. echo '    </grading>';
  25.  
  26. while($row = mysql_fetch_array($result)) {
  27.    
  28. $pregunta = array();    
  29. $pregunta[0]['nombre'] = $row['nombre'];
  30. $pregunta[0]['score'] = 1;
  31. $pregunta[1]['nombre'] = getNombre($row['sexo'], $link); //Así nos aseguramos que sea del mismo sexo!
  32. $pregunta[1]['score'] = 0;
  33. $pregunta[2]['nombre'] = getNombre($row['sexo'], $link);
  34. $pregunta[2]['score'] = 0;
  35.  
  36. $pregunta = shuffle($pregunta);  
  37.  
  38.    
  39.         printf("
  40.            <question>
  41.      <text>Pregunta</text>
  42.      [<img src='%s' alt='Profile' />]
  43.  
  44.      <option>
  45.        <text>%s</text>
  46.        <score>%s</score>
  47.      </option>
  48.  
  49.      <option>
  50.        <text>%s</text>
  51.        <score>%s</score>
  52.      </option>
  53.  
  54.      <option>
  55.        <text>%s</text>
  56.        <score>%s</score>
  57.      </option>
  58.    </question>
  59.        ", $row["img"], $row["pregunta"],$pregunta[0]['nombre'],$pregunta[0]['score'],$pregunta[1]['nombre'],$pregunta[1]['score'],$pregunta[2]['nombre'],$pregunta[2]['score'] );
  60.  
  61.  
  62.     }  
  63.    
  64. echo '  </quiz>';
  65. echo '</quizzes>';
  66. ?>