How to pull product datafeeds using PHP and MYSQL and display into your Webpage
Affiliate Project recently received a comment on this post – Niche site launched using data feeds and decided to create this post to help any other affiliates with displaying product data feeds.
We initially struggled to get product data feeds working. We found it hard to find how to get this to work, so thought we would document this on our blog and this could also help other affiliates.
There was 3 basic steps to get the data feeds to be displayed on the page.
Before you do this, you will need to download your data feeds and then create a new database using phpmyadmin (often from cpanel tools). Create the field names as per your datafeed or merchants datafeed.
1st step:
Create a php page template. So in the php file you will specify template name, pull in the header and title, then when you login to wordpress and add a new page, you can specify this new page template (your_template_name).
EXAMPLE:
<?php
/*
Template Name: your_template_name
*/
?>
<?php get_header(); ?>
<div id="content">
<span class="breadcrumbs">Browse: <strong><a href="<?php echo get_option('home'); ?>/">Home</a> » Your Template Name</strong></span>
<h2 class="title"><?php the_title(); ?></h2>
<?php
2nd step:
Put the php code that has the mysql statements that query the database which holds the datafeed
EXAMPLE:
// Connect to Database
$con = mysql_connect("localhost","database_name","database_password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Select the Database
mysql_select_db("database_name", $con);
// Select the data from table_name
$result = mysql_query("SELECT field_a, field_b, field_c, field_d, field_e FROM table_name WHERE field_f='category_name'");
3rd Step:
Display the data from the database in table format, then loop the products. After that close the connection and display the sidebar and the footer
EXAMPLE:
// Display the table
echo "<table border='0' cellspacing='16'>";
// Put results into table
$counter = 0;
while($row = mysql_fetch_array($result))
{
echo "<td WIDTH='112' align='left' valign='top'><a href=\"" .$row['field_c'] . "\">
<span class='producttable'><img width='140' src=\"" . $row['field_d'] . "\" border=1 alt=\"" . $row["field_d"] . "\" title=\"" . $row["field_b"] . "\"></span>
<br><span class='producttext'>$row[field_a]</span></br><br>$row[field_b]</br></span></a>";
echo "<br><span class='producttext'><strong>£$row[field_e]</strong></span></br>";
$counter++; # increment count every iteration
if ( $counter % 3 == 0 )
{
echo "<tr />";
}
}
echo "</td>";
echo "</table>";
// Disconnect from Database
mysql_close($con);
?>
</div>
<?php get_sidebar() ?>
<?php get_footer() ?>
You can style the output how you wish with css styling.
w3schools.com is a great resource for website coding such as html / php / mysql.
Hope this helps other affiliates.







