Foros del Web » Programando para Internet » PHP »

Como hago esto??

Estas en el tema de Como hago esto?? en el foro de PHP en Foros del Web. Hola a todos tengo una duda este es mi codigo tengo este select y me funiona bien y muestro los resultados perfectamente en xml este ...
  #1 (permalink)  
Antiguo 07/07/2010, 09:26
 
Fecha de Ingreso: abril-2010
Mensajes: 108
Antigüedad: 14 años
Puntos: 2
Pregunta Como hago esto??

Hola a todos tengo una duda
este es mi codigo
tengo este select y me funiona bien y muestro los resultados perfectamente en xml
este es el query uno
$query = "SELECT * FROM campos_dua";
$resultID = mysql_query($query, $linkID);
while($row=mysql_fetch_array($resultID))
pero yo quiero hacer otro select y desplegar el resultado en el mismo lugar del primer while
este es el query dos
$query2 = "SELECT * FROM agentes";
$resultID2 = mysql_query($query2, $linkID2);
while($row2=mysql_fetch_array($resultID2))

aqui quiero mostrar los dos resultados de los dos while
$xml_output .= "\t<DUA_CONTROL>\n";
$xml_output .= "<GLN_EMISOR_MENSAJE><![CDATA[".$row['GLN_EMISOR_MENSAJE']."]]></GLN_EMISOR_MENSAJE>";
$xml_output .= "<GLN_EMISOR_MENSAJE><![CDATA[".$row2['nombre']."]]></GLN_EMISOR_MENSAJE>";
$xml_output .= "\t</DUA_CONTROL>\n";

como puedo hacer esto

gracias jarlis pereira
  #2 (permalink)  
Antiguo 07/07/2010, 10:20
Avatar de shakaran  
Fecha de Ingreso: agosto-2005
Ubicación: España - Ciudad Real
Mensajes: 374
Antigüedad: 18 años, 8 meses
Puntos: 7
Respuesta: Como hago esto??

Es sencillo, añade el segundo query dentro del bucle while tal y como comentas:
Código PHP:
Ver original
  1. $resultID = mysql_query("SELECT * FROM campos_dua", $linkID);
  2. while($row=mysql_fetch_array($resultID))
  3. {
  4.    $resultID2 = mysql_query("SELECT * FROM agentes", $linkID2);
  5.    while($row2=mysql_fetch_array($resultID2))
  6.    {
  7.         $xml_output .= "\t<DUA_CONTROL>\n";
  8.         $xml_output .= "<GLN_EMISOR_MENSAJE><![CDATA[".$row['GLN_EMISOR_MENSAJE']."]]></GLN_EMISOR_MENSAJE>";
  9.         $xml_output .= "<GLN_EMISOR_MENSAJE><![CDATA[".$row2['nombre']."]]></GLN_EMISOR_MENSAJE>";
  10.         $xml_output .= "\t</DUA_CONTROL>\n";
  11.    }
  12. }

Fíjate que también he eliminado las variables $query y $query2 ya que en realidad las puedes meter como parámetro directamente y ahorrarte declarar las variables.
__________________
Quijost Backend Engineer - www.quijost.com - Hosting rápido, eficiente y profesional
Blog: www.shakaran.net
  #3 (permalink)  
Antiguo 07/07/2010, 10:39
 
Fecha de Ingreso: abril-2010
Mensajes: 108
Antigüedad: 14 años
Puntos: 2
Respuesta: Como hago esto??

No me muestra el resultado
Si el query dos son varios datos tiene que mostrame todos los datos
solo me muestra uno



$resultID = mysql_query("SELECT * FROM campos_dua", $linkID);

while($row=mysql_fetch_array($resultID))

{

$resultID2 = mysql_query("SELECT * FROM agentes", $linkID2);

while($row2=mysql_fetch_array($resultID2))

{

$xml_output .= "\t<DUA_CONTROL>\n";

$xml_output .= "<GLN_EMISOR_MENSAJE><![CDATA[".$row['GLN_EMISOR_MENSAJE']."]]></GLN_EMISOR_MENSAJE>";

$xml_output .= "<GLN_EMISOR_MENSAJE><![CDATA[".$row2['nombre']."]]></GLN_EMISOR_MENSAJE>";

$xml_output .= "\t</DUA_CONTROL>\n";

}

}
  #4 (permalink)  
Antiguo 07/07/2010, 10:45
Avatar de shakaran  
Fecha de Ingreso: agosto-2005
Ubicación: España - Ciudad Real
Mensajes: 374
Antigüedad: 18 años, 8 meses
Puntos: 7
Respuesta: Como hago esto??

La segunda consulta muestra perfectamente si hay dos datos.

¿Que datos tienes en las tablas?

PD: Por favor resalta el código usando el bbcode, sino se hace más pesado de leer y contestar.
__________________
Quijost Backend Engineer - www.quijost.com - Hosting rápido, eficiente y profesional
Blog: www.shakaran.net
  #5 (permalink)  
Antiguo 07/07/2010, 10:53
 
Fecha de Ingreso: abril-2010
Mensajes: 108
Antigüedad: 14 años
Puntos: 2
Pregunta Respuesta: Como hago esto??

los datos que tengo son numericos

y el resultado que quiero obtenes es asi

Este fichero XML no parece tener ninguna información de estilo asociada. Se muestra debajo el árbol del documento.

$xml_output .= "\t<DUA_CONTROL>\n";
$xml_output .= "<GLN_EMISOR_MENSAJE><![CDATA[".$row['GLN_EMISOR_MENSAJE']."]]></GLN_EMISOR_MENSAJE>";
$xml_output .= "\t<DUA_CONTROL>\n";

$xml_output .= "\t<DUA_POLIZA>\n";
$xml_output .= "<NOMBRE><![CDATA[".$row2['nombre']."]]></nombre>";
$xml_output .= "\t<DUA_POLIZA>\n";
$xml_output .= "\t<DUA_POLIZA>\n";
$xml_output .= "<NOMBRE><![CDATA[".$row2['nombre']."]]></nombre>";
$xml_output .= "\t<DUA_POLIZA>\n";

OSEA QUE SI SON VARIOS NOMBRES ME LO MOSTRARA EN EL XML

GRACIAS
  #6 (permalink)  
Antiguo 07/07/2010, 10:57
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Como hago esto??

Te recomiendo que uses SimpleXML o DOM para ingresar los resultados en formato XML. El más sencillo y fácil de usar SimpleXML.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:45.