Displaying info from different websites in a webpage

Looking to create a webpage which will compare the prices from different online shopping sites…


  1. consider i have a list of 5 websites which sell items online…
    if there is information about a PRODUCT A in MY site…
    then it shud check if that PRODUCT A is being sold by any website in the list (1),
    if yes then it should display its price…

im comfortable with wordpress, and kno how to insert and run PHP code, mysql queries… [but jst a beginer in PHP]

have no idea on how to achieve this, so any help will be appreciated…

I think you should look at product feeds. So sites may have an XML feed or an API, such as Amazon, that will allow you to pull out data to show on your website. I could be wrong but that’s what I would consider first.

IF your database(s) are on the same server and use the same database table structure you can loop through a connection of a number of databases and build an array of information, which you can then pull specific product information from, product name, sales etc. Assuming I did this right you’ll see the $sites array holds connection info for each site.

You’ll loop through connection of each DB.
Define tables to access.
Loop through and execute queries and build result array $row containing info from all databases.

$sites = array(
	"siteA" => array('databaseA', 'localhost', 'userA', 'passA'),
	"siteB" => array('databaseB', 'localhost', 'userB', 'passB'),
	"siteC" => array('databaseC', 'localhost', 'userC', 'passC')
try {
	foreach($sites as $conn => $s){
			$db = "db$x";
			$$db = new PDO("mysql:dbname={$s[0]};host={$s[1]}", "{$s[2]}", "{$s[3]}");
} catch (PDOException $ex) {
  echo 'Connection failed: ' . $ex->getMessage();
	$sqla = "SELECT * FROM `products`";
	$sqlb = "SELECT * FROM `sales`";
	$row = array();
		foreach($sites as $conn => $s){
			$resulta = "resulta$x";
			$resultb = "resultb$x";
			$db = "db$x";
			$$resulta = $$db->query($sqla);
			$$resultb = $$db->query($sqlb);
			$row[$conn][] = $$resulta->fetchAll(PDO::FETCH_ASSOC);
			$row[$conn][] = $$resultb->fetchAll(PDO::FETCH_ASSOC);

@ freakystreak thanks dats a start, could go by ur way…
thanks @Drummin for the code, but i dont have access to the db of the other website…

Well first off let me just stay that this is a huge task to take on for a beginner. There are in theory multiple ways to do this. The way which it will/can be done will be different based on each vendor that you would like to integrate. However, the top three ways to achieve this would be an integration with the vendor API, feed processing, or website scraping. The ideal way to this would be to use the vendors API to fetch the product data. Though not all vendors will have an API. If an API is not an option than the next best way to do it would via parsing some type of feed. Though not all vendors will even offer a feed. Failing that you are left with scraping the website which is a very tricky process with many points of potential failure and edge cases. The most unideal way to it would be scraping considering one change in the mark-up and the program would need to *likely be rewritten. Perhaps you could provide the community with a list of sites that you would like to aggregate/compare pricing data from. That way someone *might be able to suggest a means of fetching the data. In the case of a site like amazon an API is offered that I *believe would allow for the type of functionality desired. Though most sites out there will probably not have any type of API if even a feed. So you will only be left with the worst, most painful option of writing a scrapper(s) specific to the site that needs to be parsed. This of course is only meant to be a high level overview of the complete process. The details are dependent on the vendors/site and integration options offered if any that don’t require creating scrappers.