Comunidad de diseño web y desarrollo en internet online

crear categorias en xml

Citar            
MensajeEscrito el 11 Mar 2010 07:40 pm
saludos bueno tengo una consulta es posible crear este formato en xml?
<?xml version="1.0"?>
<category name="Hebillas">
<image>
<title>View of Seattle</title>
<desc>View of Seattle</desc>
</image>

<image>
<title>View of Seattle</title>
<desc>View of Seattle</desc>
</image>

</category>

<category name="Articulos">
<image>
<title>View of Seattle</title>
<desc>View of Seattle</desc>
</image>
<image>
<title>View of Seattle</title>
<desc>View of Seattle</desc>
</image>
</category>
</gallery>
//////////////////////////////////////////////////////////
CREATE TABLE `tabla` (
`id` int(11) NOT NULL auto_increment,
`titulo` varchar(50) NOT NULL,
`descripcion` varchar(50) NOT NULL,
`categoria` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

--
-- Volcar la base de datos para la tabla `tabla`
--

INSERT INTO `tabla` VALUES (1, 'titulo1', 'descripcion1', 'hebillas');
INSERT INTO `tabla` VALUES (2, 'titulo2', 'descripcion2', 'hebillas');
INSERT INTO `tabla` VALUES (3, 'titulo3', 'descripcion3', 'categoria2');
INSERT INTO `tabla` VALUES (4, 'titulo4', 'descripcion4', 'categoria2');

////////***************************

bueno mi script php funciona pero quiero que salga dela forma caetegorias con sus repectivos registro como meexplique alcomiexzo
<?php
/*Estas son las variables que se utilizaran para crear la conexion a tu base de datos, practicamente pues solo tendrias que colocar tus datos */
$host = "localhost";

$user = "root"; $pass = "root";

$database = "bd";



$linkID = mysql_connect($host, $user, $pass) or die("No se pudo conectar al servidor.");


mysql_select_db($database, $linkID) or die("Problemas al acceder a la base de datos");

$query = "SELECT * FROM tabla ORDER BY id DESC";

$resultID = mysql_query($query, $linkID) or die("Problemas al importar los datos.");

$xml_output = "<?xml version=\"1.0\"?>\n";

$xml_output .= "<Resultados>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ;
$x++){ $row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<entrada>\n"; $xml_output .= "\t\t<nick>" . $row['categoria'] . "</nick>\n";
$xml_output .= "\t\t<mensaje>" . $row['titulo'] . "</mensaje>\n";
$xml_output .= "\t\t<mensaje>" . $row['descripcion'] . "</mensaje>\n";
$xml_output .= "\t</entrada>\n"; } $xml_output .= "</Resultados>";


$fh = fopen("archivo.xml","w"); fwrite($fh,$xml_output); fclose($fh);
?>

agradesco de antemano cualquier alcanse muchas gracias

Por swingbeach21

Claber

104 de clabLevel



 

msie
Citar            
MensajeEscrito el 11 Mar 2010 07:47 pm
Podes hacerlo siempre que respetes el standard xml..


Despues de la etiqueta xml, necesitas una categoria padre que englobe a todas. Por ejemplo

Código XML :

<xml ...> 
<categories>
  <category>
    ... datos de la categoria
  </category>  
  <category>
  </category>
  <category>
  </category>
  <category/>
  <category/>
</categories>

Por pablofmorales

Claber

103 de clabLevel

1 tutorial

Genero:Masculino  

Web developer

firefox
Citar            
MensajeEscrito el 12 Mar 2010 03:47 pm
bueno gracias por contestar , eh cosegui escribir la inaformacion en mi xml pero lo que me flalta es alguna manera de que me bote la informacion ordenada de esta manera

<?xml version="1.0"?>
<category name="Hebillas">
<image>
<title>View of Seattle</title>
<desc>View of Seattle</desc>
</image>

<image>
<title>View of Seattle</title>
<desc>View of Seattle</desc>
</image>

</category>

<category name="Articulos">
<image>
<title>View of Seattle</title>
<desc>View of Seattle</desc>
</image>
<image>
<title>View of Seattle</title>
<desc>View of Seattle</desc>
</image>
</category>
</gallery>
:shock:

Por swingbeach21

Claber

104 de clabLevel



 

msie
Citar            
MensajeEscrito el 12 Mar 2010 07:52 pm
bueno despues de todo me salio crear categorias en xml conphp aqui dejo el codigo parque alguien que tenga el mismo problema espero que el ssirva

///*****************

<?php
/*Estas son las variables que se utilizaran para crear la conexion a tu base de datos, practicamente pues solo tendrias que colocar tus datos */
$host = "localhost";

$user = "root"; $pass = "root";

$database = "bd";

/* Ahora si, comenzamos iniciando la conexion, de la forma siguiente, y agregamos los "or die" por si algo ocurre antes de realizar la conexion nos lo indique */

$linkID = mysql_connect($host, $user, $pass) or die("No se pudo conectar al servidor.");


mysql_select_db($database, $linkID) or die("Problemas al acceder a la base de datos");
//creando querys---------------------------------------------------------------------------
$query = "SELECT * FROM tabla where categoria ='1' ORDER BY id DESC";

$resultID = mysql_query($query, $linkID) or die("Problemas al importar los datos.");
//------------------------------------------------------------------------------------
$query2 = "SELECT * FROM tabla where categoria ='2' ORDER BY id DESC";

$resultID2 = mysql_query($query2, $linkID) or die("Problemas al importar los datos.");
//----------------------------------------------------------------------------------------
$query3 = "SELECT * FROM tabla where categoria ='3' ORDER BY id DESC";

$resultID3 = mysql_query($query3, $linkID) or die("Problemas al importar los datos.");

//------------------------------------------------------------------
$query4 = "SELECT * FROM tabla where categoria ='4' ORDER BY id DESC";

$resultID4 = mysql_query($query4, $linkID) or die("Problemas al importar los datos.");

//------------------------------------------------------------------------------------------

$query5 = "SELECT * FROM tabla where categoria ='5' ORDER BY id DESC";

$resultID5 = mysql_query($query5, $linkID) or die("Problemas al importar los datos.");

//-------------------------------------------------------------------------------------------
$query6 = "SELECT * FROM tabla where categoria ='6' ORDER BY id DESC";

$resultID6 = mysql_query($query6, $linkID) or die("Problemas al importar los datos.");

//------------------------------------------------------------------------------------------
$xml_output = "<?xml version=\"1.0\"?>\n";

$xml_output .= "<gallery thumbDir=\"./images/thumbs/\" imageDir=\"./images/\" random=\"true\">\n";
$xml_output .= "\t<category name=\"Accesorios\">\n";

for($x = 0 ; $x < mysql_num_rows($resultID) ;
$x++){ $row = mysql_fetch_assoc($resultID);
$xml_output .= "\t\t<image>\n";
$xml_output .= "\t\t\t<date>" . $row['date'] . "</date>\n";
$xml_output .= "\t\t\t<title>" . $row['titulo'] . "</title>\n";
$xml_output .= "\t\t\t<desc>" . $row['descripcion'] . "</desc>\n";
$xml_output .= "\t\t\t<thumb>" . $row['fotopeque'] . "</thumb>\n";
$xml_output .= "\t\t\t<img>" . $row['fotogrande'] . "</img>\n";
$xml_output .= "\t\t</image>\n";
} $xml_output .= "\t</category>\n";
///------------------------------
$xml_output .= "\t<category name=\"Estribos\">\n";

for($b = 0 ; $b < mysql_num_rows($resultID2) ;
$b++){ $row2 = mysql_fetch_assoc($resultID2);
$xml_output .= "\t\t<image>\n";
$xml_output .= "\t\t\t<date>" . $row['date'] . "</date>\n";
$xml_output .= "\t\t\t<title>" . $row['titulo'] . "</title>\n";
$xml_output .= "\t\t\t<desc>" . $row['descripcion'] . "</desc>\n";
$xml_output .= "\t\t\t<thumb>" . $row['fotopeque'] . "</thumb>\n";
$xml_output .= "\t\t\t<img>" . $row['fotogrande'] . "</img>\n";
$xml_output .= "\t\t</image>\n";
}$xml_output .= "\t</category>\n";

///------------------------------
$xml_output .= "\t<category name=\"Hebillas\">\n";

for($c = 0 ; $c < mysql_num_rows($resultID3) ;
$c++){ $row3 = mysql_fetch_assoc($resultID3);
$xml_output .= "\t\t<image>\n";
$xml_output .= "\t\t\t<date>" . $row['date'] . "</date>\n";
$xml_output .= "\t\t\t<title>" . $row['titulo'] . "</title>\n";
$xml_output .= "\t\t\t<desc>" . $row['descripcion'] . "</desc>\n";
$xml_output .= "\t\t\t<thumb>" . $row['fotopeque'] . "</thumb>\n";
$xml_output .= "\t\t\t<img>" . $row['fotogrande'] . "</img>\n";
$xml_output .= "\t\t</image>\n";
} $xml_output .= "\t</category>\n";

///------------------------------
$xml_output .= "\t<category name=\"Articulos Publicitarios\">\n";

for($d = 0 ; $d < mysql_num_rows($resultID4) ;
$d++){ $row4 = mysql_fetch_assoc($resultID4);
$xml_output .= "\t\t<image>\n";
$xml_output .= "\t\t\t<date>" . $row['date'] . "</date>\n";
$xml_output .= "\t\t\t<title>" . $row['titulo'] . "</title>\n";
$xml_output .= "\t\t\t<desc>" . $row['descripcion'] . "</desc>\n";
$xml_output .= "\t\t\t<thumb>" . $row['fotopeque'] . "</thumb>\n";
$xml_output .= "\t\t\t<img>" . $row['fotogrande'] . "</img>\n";
$xml_output .= "\t\t</image>\n";
}$xml_output .= "\t</category>\n";
///------------------------------
$xml_output .= "\t<category name=\"Liquidacion\">\n";

for($e = 0 ; $e < mysql_num_rows($resultID5) ;
$e++){ $row5 = mysql_fetch_assoc($resultID5);
$xml_output .= "\t\t<image>\n";
$xml_output .= "\t\t\t<date>" . $row['date'] . "</date>\n";
$xml_output .= "\t\t\t<title>" . $row['titulo'] . "</title>\n";
$xml_output .= "\t\t\t<desc>" . $row['descripcion'] . "</desc>\n";
$xml_output .= "\t\t\t<thumb>" . $row['fotopeque'] . "</thumb>\n";
$xml_output .= "\t\t\t<img>" . $row['fotogrande'] . "</img>\n";
$xml_output .= "\t\t</image>\n";
}
$xml_output .= "\t</category>\n";
///------------------------------
$xml_output .= "\t<category name=\"Novedades\">\n";

for($f = 0 ; $f < mysql_num_rows($resultID6) ;
$f++){ $row6 = mysql_fetch_assoc($resultID6);
$xml_output .= "\t\t<image>\n";
$xml_output .= "\t\t\t<date>" . $row['date'] . "</date>\n";
$xml_output .= "\t\t\t<title>" . $row['titulo'] . "</title>\n";
$xml_output .= "\t\t\t<desc>" . $row['descripcion'] . "</desc>\n";
$xml_output .= "\t\t\t<thumb>" . $row['fotopeque'] . "</thumb>\n";
$xml_output .= "\t\t\t<img>" . $row['fotogrande'] . "</img>\n";
$xml_output .= "\t\t</image>\n";
}
///------

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


$fh = fopen("archivo.xml","w"); fwrite($fh,$xml_output); fclose($fh);
?>
:cool:

Por swingbeach21

Claber

104 de clabLevel



 

msie
Citar            
MensajeEscrito el 12 Mar 2010 07:58 pm
nunca vi tanto codigo para hacer algo tan simple

Por pablofmorales

Claber

103 de clabLevel

1 tutorial

Genero:Masculino  

Web developer

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.