Na klik naar xml
mariosss - 19/05/2009 14:18 (laatste wijziging 19/05/2009 14:38)
Nieuw lid
Hallo,
Ik heb een php bestand waarin gegevens worden opgehaald uit de database. Staat netjes in tabellen. Nu wil ik ervoor zorgen dat dit wordt omgezet naar xml, en dat deze word opgeslagen naar een bepaalde locatie. Ik weet alleen niet met welke functies dit kan. Dit moet dus automatisch gebeuren na een klik op dit php bestand.
Wie kan me helpen?
Alvast bedankt.
8 antwoorden
Gesponsorde links
kurohyou - 19/05/2009 14:57
Oud lid
wat wil je juist doen? wat ik uit je post versta is dat je gegevens uit een mysql tabel wilt omzetten naar xml? nee?
mariosss - 19/05/2009 15:01 (laatste wijziging 19/05/2009 15:02)
Nieuw lid
Ja zoiets. Eerst komen de gegevens in dit php bestand terecht, daarna de functie xml. Maar dit moet dus automatisch gebeuren, nadat ik in een andere pagina dit bestand aanroep. Dus dat die dan die de gegevens leest, en daarna naar xml omzet en dan gaat opslaan ergens in een map.
Ergens in de code hieronder zou ik dus die code moeten plaatsen maar zou echt niet weten waar en wat:
<html>
<head>
<title>uitvoer</title>
</head>
<?php
mysql_connect('localhost','....','......');
mysql_select_db('....') or die (mysql_error());
$res = mysql_query("SELECT * FROM orders INNER JOIN orders_products ON (orders.orders_id = orders_products.orders_id ) ")or die(mysql_error()) ;
while ($obj = mysql_fetch_object($res)) { ?>
<table border="1" width="4000">
<tr>
<td bgcolor="#efefef" width="15"><?echo $obj->orders_id."";?></td>
<td bgcolor="#efefef" width="200"><?echo $obj->customers_name."<br />"; ?></td>
<td bgcolor="#efefef" width="100"><?echo $obj->customers_company."<br />"; ?></td>
<td bgcolor="#efefef" width="150"><?echo $obj->customers_street_address."<br />"; ?></td>
<td bgcolor="#efefef" width="100"><?echo $obj->customers_city."<br />"; ?></td>
<td bgcolor="#efefef" width="100"><?echo $obj->customers_postcode."<br />"; ?></td>
<td bgcolor="#efefef" width="100"><?echo $obj->customers_state."<br />"; ?></td>
<td bgcolor="#efefef" width="100"><?echo $obj->customers_country."<br />"; ?></td>
<td bgcolor="#efefef" width="100"><?echo $obj->customers_telephone."<br />"; ?></td>
<td bgcolor="#efefef" width="100"><?echo $obj->customers_email_address."<br />"; ?></td>
<td bgcolor="#ffffee" width="100"><?echo $obj->delivery_name."<br />"; ?></td>
<td bgcolor="#ffffee" width="100"><?echo $obj->delivery_company."<br />"; ?></td>
<td bgcolor="#ffffee" width="150"><?echo $obj->delivery_street_address."<br />"; ?></td>
<td bgcolor="#ffffee" width="100"><?echo $obj->delivery_city."<br />"; ?></td>
<td bgcolor="#ffffee" width="100"><?echo $obj->delivery_postcode."<br />"; ?></td>
<td bgcolor="#ffffee" width="100"><?echo $obj->delivery_state."<br />"; ?></td>
<td bgcolor="#ffffee" width="100"><?echo $obj->delivery_country."<br />"; ?></td>
<td bgcolor="#ffffvv" width="100"><?echo $obj->billing_name."<br />"; ?></td>
<td bgcolor="#ffffvv" width="100"><?echo $obj->billing_company."<br />"; ?></td>
<td bgcolor="#ffffvv" width="150"><?echo $obj->billing_street_address."<br />"; ?></td>
<td bgcolor="#ffffvv" width="100"><?echo $obj->billing_city."<br />"; ?></td>
<td bgcolor="#ffffvv" width="100"><?echo $obj->billing_postcode."<br />"; ?></td>
<td bgcolor="#ffffvv" width="100"><?echo $obj->billing_state."<br />"; ?></td>
<td bgcolor="#ffffvv" width="100"><?echo $obj->billing_country."<br />"; ?></td>
<td bgcolor="#FF0000" width="100"><font size="3"><?echo $obj->payment_method."<br />"; ?></td>
<td bgcolor="#FF0000" width="100"><font size="1"><?echo $obj->date_purchased."<br />"; ?></td>
<td bgcolor="#FF0000" width="200"><font size="1"><?echo $obj->products_name."<br />"; ?></td>
<td bgcolor="#FF0000" width="100"><?echo $obj->products_quantity."<br />"; ?></td>
</tr>
</table>
<?
}
mysql_free_result($res);
?>
<br>
<br>
<table>
<tr>
<td bgcolor="#efefef">=Klant gegevens</td>
</tr>
<td bgcolor="#ffffee">=Bezorg gegevens</td>
</tr>
<td bgcolor="#ffffvv">=Factuur gegevens</td>
</tr>
<td bgcolor="#FF0000">=Bestel gegevens</td>
</tr>
</table>
<html>
<head>
<title>uitvoer</title>
</head>
<?php
$res = mysql_query ( "SELECT * FROM orders INNER JOIN orders_products ON (orders.orders_id = orders_products.orders_id ) " ) or
die ( mysql_error ( ) ) ;
<table border="1" width="4000">
<tr>
<td bgcolor="#efefef" width="15">
< ?
echo $obj -> orders_id . "" ; ?
> </td>
<td bgcolor="#efefef" width="200">
< ?
echo $obj -> customers_name . "<br />" ; ?> </td>
<td bgcolor="#efefef" width="100">
< ?
echo $obj -> customers_company . "<br />" ; ?> </td>
<td bgcolor="#efefef" width="150">
< ?
echo $obj -> customers_street_address . "<br />" ; ?> </td>
<td bgcolor="#efefef" width="100">
< ?
echo $obj -> customers_city . "<br />" ; ?> </td>
<td bgcolor="#efefef" width="100">
< ?
echo $obj -> customers_postcode . "<br />" ; ?> </td>
<td bgcolor="#efefef" width="100">
< ?
echo $obj -> customers_state . "<br />" ; ?> </td>
<td bgcolor="#efefef" width="100">
< ?
echo $obj -> customers_country . "<br />" ; ?> </td>
<td bgcolor="#efefef" width="100">
< ?
echo $obj -> customers_telephone . "<br />" ; ?> </td>
<td bgcolor="#efefef" width="100">
< ?
echo $obj -> customers_email_address . "<br />" ; ?> </td>
<td bgcolor="#ffffee" width="100">
< ?
echo $obj -> delivery_name . "<br />" ; ?> </td>
<td bgcolor="#ffffee" width="100">
< ?
echo $obj -> delivery_company . "<br />" ; ?> </td>
<td bgcolor="#ffffee" width="150">
< ?
echo $obj -> delivery_street_address . "<br />" ; ?> </td>
<td bgcolor="#ffffee" width="100">
< ?
echo $obj -> delivery_city . "<br />" ; ?> </td>
<td bgcolor="#ffffee" width="100">
< ?
echo $obj -> delivery_postcode . "<br />" ; ?> </td>
<td bgcolor="#ffffee" width="100">
< ?
echo $obj -> delivery_state . "<br />" ; ?> </td>
<td bgcolor="#ffffee" width="100">
< ?
echo $obj -> delivery_country . "<br />" ; ?> </td>
<td bgcolor="#ffffvv" width="100">
< ?
echo $obj -> billing_name . "<br />" ; ?> </td>
<td bgcolor="#ffffvv" width="100">
< ?
echo $obj -> billing_company . "<br />" ; ?> </td>
<td bgcolor="#ffffvv" width="150">
< ?
echo $obj -> billing_street_address . "<br />" ; ?> </td>
<td bgcolor="#ffffvv" width="100">
< ?
echo $obj -> billing_city . "<br />" ; ?> </td>
<td bgcolor="#ffffvv" width="100">
< ?
echo $obj -> billing_postcode . "<br />" ; ?> </td>
<td bgcolor="#ffffvv" width="100">
< ?
echo $obj -> billing_state . "<br />" ; ?> </td>
<td bgcolor="#ffffvv" width="100">
< ?
echo $obj -> billing_country . "<br />" ; ?> </td>
<td bgcolor="#FF0000" width="100"><font size="3">
< ?
echo $obj -> payment_method . "<br />" ; ?> </td>
<td bgcolor="#FF0000" width="100"><font size="1">
< ?
echo $obj -> date_purchased . "<br />" ; ?> </td>
<td bgcolor="#FF0000" width="200"><font size="1">
< ?
echo $obj -> products_name . "<br />" ; ?> </td>
<td bgcolor="#FF0000" width="100">
< ?
echo $obj -> products_quantity . "<br />" ; ?> </td>
</tr>
</table>
<?
}
?>
<br>
<br>
<table>
<tr>
<td bgcolor="#efefef">=Klant gegevens</td>
</tr>
<td bgcolor="#ffffee">=Bezorg gegevens</td>
</tr>
<td bgcolor="#ffffvv">=Factuur gegevens</td>
</tr>
<td bgcolor="#FF0000">=Bestel gegevens</td>
</tr>
</table>
kurohyou - 19/05/2009 15:53 (laatste wijziging 19/05/2009 17:33)
Oud lid
probeer dit eens
define(’ROOT_PATH’, $_SERVER['DOCUMENT_ROOT']);
//XML write function
function writeXML($xmlfile, $tablename)
{
$xmlfile_path= ROOT_PATH.”/”.$xmlfile;
$res = mysql_query("SELECT * FROM orders INNER JOIN orders_products ON (orders.orders_id = orders_products.orders_id ) ")or die(mysql_error()) ;
$xmlstore=”;
$xmlstore .=”;
while($obj = mysql_fetch_object($res)) {
$xmlstore .=”.$obj->orders_id.";
$xmlstore .=”.$obj->customers_name.";
$xmlstore .=".$obj ->lijstje afgaan
$xmlstore .=".volgende ...
$xmlstore .=”;
}
$xmlstore .=”;
$handle = fopen($xmlfile_path, ‘w’);
fwrite($handle, $xmlstore);
}
//Put XML file name and mysql table name simultaniously
writeXML(’sample.xml’, ’sampletable’);
define ( ’ROOT_PATH’
, $_SERVER [ 'DOCUMENT_ROOT' ] ) ;
//XML write function
function writeXML( $xmlfile , $tablename )
{
$xmlfile_path = ROOT_PATH. ”/ ”. $xmlfile ;
$res = mysql_query ( "SELECT * FROM orders INNER JOIN orders_products ON (orders.orders_id = orders_products.orders_id ) " ) or
die ( mysql_error ( ) ) ;
$xmlstore = ”;
$xmlstore .= ”;
$xmlstore .= ”. $obj -> orders_id . ";
$xmlstore .=”.$obj->customers_name .";
$xmlstore .= ".$obj ->lijstje afgaan
$xmlstore .=". volgende ...
$xmlstore .= ”;
}
$xmlstore .= ”;
$handle = fopen ( $xmlfile_path , ‘w’
) ;
}
//Put XML file name and mysql table name simultaniously
writeXML( ’sample. xml’, ’sampletable’) ;
mariosss - 19/05/2009 16:09 (laatste wijziging 19/05/2009 16:10)
Nieuw lid
ik heb het even zo geprobeerd, maar hij doet het niet:
<?
mysql_connect('localhost','.....','.....');
mysql_select_db('shop') or die (mysql_error());
while ($obj = mysql_fetch_object($res)) {
define(’ROOT_PATH’, $_SERVER['DOCUMENT_ROOT']);
//XML write function
function writeXML($xmlfile, $tablename)
{
$xmlfile_path= ROOT_PATH.”/”.$xmlfile;
$res = mysql_query("SELECT * FROM orders INNER JOIN orders_products ON (orders.orders_id = orders_products.orders_id ) ")or die(mysql_error()) ;
$xmlstore=”;
$xmlstore .=”;
while($obj = mysql_fetch_object($res)) {
$xmlstore .=".$obj->orders_id.";
$xmlstore .=".$obj->customers_name.";
$xmlstore .=".$obj->customers_company.";
$xmlstore .=".$obj->customers_city.";
$xmlstore .=".$obj->customers_postcode.";
$xmlstore .=".$obj->customers_state.";
$xmlstore .=".$obj->customers_country.";
$xmlstore .=".$obj->customers_telephone.";
$xmlstore .=".$obj->customers_email_address.";
$xmlstore .=".$obj->delivery_name.";
}
$xmlstore .=”;
$handle = fopen($xmlfile_path, ‘w’);
fwrite($handle, $xmlstore);
}
//Put XML file name and mysql table name simultaniously
writeXML(’sample.xml’, ’sampletable’);
?>
<?
define ( ’ROOT_PATH’
, $_SERVER [ 'DOCUMENT_ROOT' ] ) ;
//XML write function
function writeXML( $xmlfile , $tablename )
{
$xmlfile_path = ROOT_PATH. ”/ ”. $xmlfile ;
$res = mysql_query ( "SELECT * FROM orders INNER JOIN orders_products ON (orders.orders_id = orders_products.orders_id ) " ) or
die ( mysql_error ( ) ) ;
$xmlstore = ”;
$xmlstore .= ”;
$xmlstore .= ".$obj->orders_id ." ;
$xmlstore .= ".$obj->customers_name ." ;
$xmlstore .= ".$obj->customers_company ." ;
$xmlstore .= ".$obj->customers_city ." ;
$xmlstore .= ".$obj->customers_postcode ." ;
$xmlstore .= ".$obj->customers_state ." ;
$xmlstore .= ".$obj->customers_country ." ;
$xmlstore .= ".$obj->customers_telephone ." ;
$xmlstore .= ".$obj->customers_email_address ." ;
$xmlstore .= ".$obj->delivery_name ." ;
}
$xmlstore .= ”;
$handle = fopen ( $xmlfile_path , ‘w’
) ;
}
//Put XML file name and mysql table name simultaniously
writeXML( ’sample. xml’, ’sampletable’) ;
?>
vinTage - 19/05/2009 17:31
Nieuw lid
Volgens mij zijn een hoop van je quotes niet juist, zoals bijvoorbeeld:
Citaat:
$xmlstore=”;
$xmlstore .=”;
’sample.xml’, ’sampletable’
‘w’
?
Wave6 - 19/05/2009 18:07
PHP beginner
Gebruik simpleXml ;)
Gesponsorde links
Dit onderwerp is gesloten .