...

View Full Version : Creating an XML file using data from an Ecommerce website...



twilight85
09-29-2008, 03:11 PM
I am working on an e-commerce website that is well established. The products were manually placed into the database. Is it possible to grab all the product details and place them in an xml and cvs file so I can feed them into other websites?

nine72
09-29-2008, 11:33 PM
I am not sure about making them in to a csv as I have not done that.

I have a mySql db that stores information from a load of forms (could be existing data also) I grab it all via a sql query and then generate an xml string and send the a specified url using cURL.

Exp:

Query



session_start();

require_once("../../Connections/dbadd.php");

$transactionId = $_SESSION['form_data']['transactionId'];

//Query to select ALL from dbadd db //
//transactionId as key

$xmlVarSet = "SELECT * FROM aib
LEFT JOIN cd ON aib.transactionId = cd.transactionId
LEFT JOIN cp ON aib.transactionId = cp.transactionId
LEFT JOIN fd_a ON aib.transactionId = fd_ach.transactionId
LEFT JOIN fd_c ON aib.transactionId = fd_cc.transactionId
LEFT JOIN fd_d ON aib.transactionId = fd_dbt.transactionId
LEFT JOIN fe ON aib.transactionId = fe.transactionId
LEFT JOIN rf ON aib.transactionId = rf.transactionId
LEFT JOIN st ON aib.transactionId = st.transactionId
LEFT JOIN ct ON aib.transactionId = ct.transactionId
WHERE aib.transactionId = '$transactionId';";



Generate the xml string something like this….



include_once("../../gatewayapi/inc_gatewayapi.php");
require_once("../../Connections/dbadd.php");
require_once("../../db_calls/get_session.php");

function StripSpecChar($val) {
return (preg_replace('/[^a-zA-Z0-9" "-.@]/','', $val));
}

$query = ($xmlVarSet);
$res = mysql_query($query)or die(mysql_error());
if($res){
while($row = mysql_fetch_assoc($res)){
foreach($row as $key => $val){
$_SESSION['db'][$key] = StripSpecChar($val);
}
}
}

$xmlString .= "< NewAdd xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation='NewAdd.xsd'>\n";


// ****** LOGIN PART ******

$xmlString .= "<Login>\n";
$xmlString .= "<transactionId>". $_SESSION[‘db’][‘transactionId’] . "</transactionId>\n";
$xmlString .= "</Login>\n";

// ****** SUBMISSION TYPE ******
$xmlString .= "<All>\n";
$xmlString .= "<Corporate>\n";
$xmlString .= "<CpBus>\n";
$xmlString .= "<agent_id>". $_SESSION['db']['agentId'] ."</agent_id>\n";
$xmlString .= "<iso_id>". $_SESSION['db']['isoId'] . "</iso_id>\n";
$xmlString .= "<bb_id>". $_SESSION['db']['bbId'] . "</bb_id>\n";
$xmlString .= "<cp_legal_name>". $_SESSION['db']['cpLegalName'] . "</cp_legal_name>\n";
$xmlString .= "<cp_dba_name>". $_SESSION['db']['cpDbaName'] . "</cp_dba_name>\n";
$xmlString .= "</CpBus>\n";
$xmlString .= "</Corporate>\n";
$xmlString . = "</All>\n";

$xmlString .= "</NewAdd>\n";



I then make a connection using cURL and send to what every URL is designated….
Don’t know if that helps and I am sure that there are easier ways to do it but this is what I have and your question sounded along the same lines.

Cheers.

oesxyl
09-30-2008, 04:25 AM
I am working on an e-commerce website that is well established. The products were manually placed into the database. Is it possible to grab all the product details and place them in an xml and cvs file so I can feed them into other websites?
for csv you can use:

http://www.php.net/manual/en/function.fputcsv.php

along with nine72 suggestion for xml.

PS: I assume you want csv - comma separated format not cvs - control version system.

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum