Hoi idereen

Ik wil twee tabellen combineren in een xml met de volgende fomat

<Transaction>
	<reference>070410171953</reference> //tabel 1
	<customer>Tafel 8</customer> //tabel 1
	<TransactionLines>
		<product>Bier van het vat            </product> //tabel 2
	</TransactionLines>
	<TransactionLines>
		<product>Bier van het vat            </product> //tabel 2
	</TransactionLines>
	<TransactionLines>
		<product>Huiswijn wit glas           </product> //tabel 2
	</TransactionLines>
	<TransactionLines>
		<product>Psaronefri                  </product> //tabel 2
	</TransactionLines>
	<TransactionLines>
		<product>Suflaki                     </product> //tabel 2
	</TransactionLines>
</Transaction>


Deze code werkt maat ik moet de 30sec timeout op de server uitzetten, dat kan ik op mijn local maar niet op de online server.

<?php
mysql_connect("localhost", "root", "" );
mysql_select_db("pos");

$sql1 = "SELECT reference, customer FROM receipts ";
$result1 = mysql_query($sql1) or die ( mysql_error() );

$xml_output = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\n";
$xml_output .= "<Data>\n";
while ($row1 = mysql_fetch_assoc($result1) )
{
$receiptsreference=$row1['reference'];
$xml_output .= "<Transactions>\n";

$xml_output .= "<reference>" . $row1['reference']. "</reference>";
$xml_output .= "<customer>" . $row1['customer'] . "</customer>\n";

$sql2 = "SELECT product FROM orders WHERE reference = $receiptsreference";
$result2 = mysql_query($sql2) or die ( mysql_error() );

while ($row2 = mysql_fetch_assoc($result2) )
{
$xml_output .= "<TransactionLines>";
$xml_output .= "<product>" . $row2['product']. "</product>";
$xml_output .= "</TransactionLines>\n";
}
$xml_output .= "</Transactions>\n";
}
$xml_output .= "</Data>";
$XMLFile = fopen("myxmlfile.xml", "w");
fwrite($XMLFile, $xml_output);
fclose($XMLFile);
?>

Hoe kan ik de script beter, sneller maken zodat niet met de timeout error heb te maken?

Bij voorbaat dank Dimitris
1. Door de data zodanig op te halen dat je het afkunt met 1 query
2. Door niet het principe van "string plakken" te gebruiken
http://www.php.net/DOM
http://www.php.net/xmlwriter

3. Je te verdiepen in de mogelijkheden van mysql

maar dan nog zal je tegen de time out aan kunnen lopen
m.a.w. je moet dit niet laten lopen via de webserver

Reageren