Ver Mensaje Individual
  #3 (permalink)  
Antiguo 02/03/2009, 10:25
gtuxyco
 
Fecha de Ingreso: febrero-2009
Mensajes: 7
Antigüedad: 17 años, 7 meses
Puntos: 0
Respuesta: PHP generar XML apartir de Recordset MYSQL

Bueno despues de buscar mucho encontre un codigo que funciona...
pero no crea el xml si no que lo muestra en pantalla.
El codigo es el siguiente
Código PHP:
<?php


// Informacion de conexion a base de datos
$dbhost    = 'localhost';
$dbname    = 'xxxxxx';
$dbuser    = 'xxxxx';
$dbpasswd  = 'xxxxx';
// adjust the URL to yours
$url       = 'video.php?id=';


// Conecate a la base de datos
$dbcnx     = mysql_connect($dbhost, $dbuser, $dbpasswd) or die("Could not connect to host: " . $dbhost);
$dbselect  = mysql_select_db($dbname) or die("Could not connect to database: " . $dbselect);

if ((!
$dbcnx) || (!$dbselect))
{
  echo 
"Can't connect to database";
}


// Toma los datos de la base..
$query  = sprintf("SELECT title, videoservercode, picturelink, itemcomment FROM #__items");
$result = mysql_query($query, $dbcnx) or die ("Could not select the menu name\n<br>\n" . mysql_error() . "\n<br>\n" . $query_1 . "\n");


//Imprime los datos en pantalla
header("Content-Type: text/xml;charset=UTF-8");
print <<<END
<playlist version='1' xmlns='hxxp://xspf.org/ns/0/'>
  <title>Playlist generada</title>
  <info>$url</info>
    <trackList>

END;

while(
$data_array = mysql_fetch_array($result))
{
  print <<<END
    <track>
      <title>
{$data_array['title']}</title>
      <location>
{$url}{$data_array['videoservercode']}</location>
      <image>
{$data_array['picturelink']}</image>
      <annotation>
{$data_array['itemcomment']}</annotation>
      </track>

END;
}

print <<<END
  </trackList>
</playlist>

END;
?>
Pero ahora quiero ponerle la funcion fwrite y no he podido...
Cuando lo pongo no escribe nada

Código PHP:
// Crea XML
$name_file="video.xml";
$file=fopen($name_file,"w+");
fwrite ($file,$xml);
fclose($file); 
Pues lo que yo estoy haciendo es convertir toda las lineas que imprimen el resultado en la funcion $xml
pero no me bota nada..
:)
Y todabia no he podido hacer lo que dijiste del limit no c como se hace