You are here:  » Using price tapestry DB from one site on another

Support Forum



Using price tapestry DB from one site on another

Submitted by clare on Wed, 2007-10-10 15:09 in

Is it possible by doing something in the $config_baseHREF to access products from one domains PT installation, in a price tapestry installation on another website.

Say for example I wanted to query the beauty categry installation of price tapestry on another website, can I install PT on the other website and then configure it to query the DB of the beauty category installation on the other website?

Or do I have to copy the DB over to the other website in order to do that?

Submitted by support on Wed, 2007-10-10 16:10

Hi Clare,

You can have more than one installation pointing at the same database - no problem at all. Simply enter the appropriate database details in config.php and away you go. It may be a little more complicated if you only want to do certain operations on the other database, as this will involve overriding the database settings on a query-by-query basis - which can be done if that is what you're looking to do...

Cheers,
David.

Submitted by clare on Sat, 2007-11-03 09:53

Hi,
Yes, what I would like to do is show a menu of categories on a page outside the installation folder. Ot anything like that.

So for example, I have 2 PT installation, UK & USA, both in subfolders, mysite.com/uk and mysite.com/usa

Then in the root of the site mysite.com I have a page that I want to show something from one or the other or both installations on.

So here is one thing I am tryiing to do. On a root level page outside the PT installation folder, put the dropdown menu showing the categories, the code for which if the page were within the PT installation folder would be

<?php
print "<form name='form' id='form'>";
    print "<select name='jumpMenu' id='jumpMenu' onchange=\"MM_jumpMenu('parent',this,1)\">";
print "<option>-- Select Gift Range --</option>";
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER by category";
    database_querySelect($sql,$rows);
    foreach($rows as $row)
{
   print "<option value='http://www.hairstylezone.com/christmas-gifts-uk/category/".urlencode(str_replace(" ","-",$row["category"]))."/'>".$row["category"]."</option>";
}
    print "</select>";
print "<noscript><input type='submit' value='Go'></noscript>";
print "</form>";
?>

So is there a way when taking code normally used within the installation folder, to adapt it for a page outside, I am guessing I have to put some includes with absolute urls to the installation folder, but am not really sure.

Submitted by support on Sat, 2007-11-03 10:03

Hi Clare,

All you need to do is include the common database library from one site, and then the config.php from the site you wish to query just before the code to query that site. For example:

<?php
  
// ***********************
  // just include this once:
  
require("christmas-gifts-uk/includes/database.php");
  
// ************************************************
  // and then this before querying christmas-gifts-uk
  
require("christmas-gifts-uk/config.php");
  print 
"<form name='form' id='form'>";
  print 
"<select name='jumpMenu' id='jumpMenu' onchange=\"MM_jumpMenu('parent',this,1)\">";
  print 
"<option>-- Select Gift Range --</option>";
  
$sql "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER by category";
  
database_querySelect($sql,$rows);
  foreach(
$rows as $row)
  {
    print 
"<option value='http://www.hairstylezone.com/christmas-gifts-uk/category/".urlencode(str_replace(" ","-",$row["category"]))."/'>".$row["category"]."</option>";
  }
  print 
"</select>";
  print 
"<noscript><input type='submit' value='Go'></noscript>";
  print 
"</form>";
  
// *************************************************
  // and then this before querying christmas-gifts-usa
  
require("christmas-gifts-usa/config.php");
  print 
"<form name='form' id='form'>";
  print 
"<select name='jumpMenu' id='jumpMenu' onchange=\"MM_jumpMenu('parent',this,1)\">";
  print 
"<option>-- Select Gift Range --</option>";
  
$sql "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER by category";
  
database_querySelect($sql,$rows);
  foreach(
$rows as $row)
  {
    print 
"<option value='http://www.hairstylezone.com/christmas-gifts-usa/category/".urlencode(str_replace(" ","-",$row["category"]))."/'>".$row["category"]."</option>";
  }
  print 
"</select>";
  print 
"<noscript><input type='submit' value='Go'></noscript>";
  print 
"</form>";
?>

Hope this helps,
Cheers,
David.

Submitted by clare on Sat, 2007-11-03 10:11

Yes thats great thanks very much.

Submitted by clare on Sat, 2007-11-03 14:06

Actually I am still having problems, although the above code works perfectly
http://www.hairstylezone dot com/test.html

I am in fact using it as part of some more php code that recognises the visitors country and shows certain
code depending on their location. So I am trying to put this code as an echo, but this way is causing an error.

Do you know are there some restrictions as to what can be put in an echo string as I am doing like this ...

<?php
if ($countrySHORT == "UK")
{
 // If the visitors are from UK, show advertisement from UK
 echo "
 UK CODE
    ";
}
else {
// Otherwise, show other advertisement
 echo "
USA CODE
 ";
}
?>

Where UK CODE I have put the code you showed me to display the UK category dropdown and where USA CODE I put same for USA dropdown.

I have tried to escape the quotations using \ and also changing the " to '

But I keep getting same error where saying that line 20 which is

 foreach($rows as $row)
  {
    print \"<option value='http://www.hairstylezone.com/christmas-gifts-uk/category/\".urlencode(str_replace(\" \",\"-\",$row[\"category\"])).\"/'>\".$row[\"category\"].\"</option>\";
  }

Can you see anything in that line of code that cannot be put in an echo statement of this kind?

Or could the problem be occuring due to the database that the country specific php is connecting to is interfering with accessing the PT database?

Submitted by support on Sat, 2007-11-03 17:31

Hi Clare,

You shouldn't need to escape anything at that point, as your script is already in PHP mode, so instead of the echo statement, simply insert the foreach and print statement directly, for example:

 foreach($rows as $row)
  {
    print "<option value='http://www.hairstylezone.com/christmas-gifts-uk/category/".urlencode(str_replace(" ","-",$row["category"]))."/'>".$row["category"]."</option>";
  }

Cheers,
David.

Submitted by clare on Sun, 2007-11-04 09:04

Thanks David, of course, why didnt I think of that??

Submitted by clare on Sun, 2007-11-04 10:48

Hi, what about for showing the featured products using the code below...database.php and config are already declared I think from showing the categories on same page, I tried including common.php but am just getting errors saying that certain functions are undefined, so is there some other file required as well, when outside the installation..or is it possible?

 print javascript_focus("search.q");
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
  if (database_querySelect($sql,$rows))
  {
    $sqlNames = array();
    foreach($rows as $featured)
    {
      $sqlNames[] = "'".$featured["name"]."'";
    }
    $sqlIn = implode(",",$sqlNames);
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";
    database_querySelect($sql,$rows);
    $featured["products"] = $rows;
    foreach($featured["products"] as $k => $product)
    {
      if ($config_useRewrite)
      {
        $featured["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
        $featured["products"][$k]["reviewHREF"] = "review/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $featured["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
        $featured["products"][$k]["reviewHREF"] = "reviews.php?q=".urlencode($product["name"]);
      }
    }
  }
  if (isset($featured)) require("http://www.mysite.com/christmas-gifts-uk/html/featured.php");

Submitted by support on Sun, 2007-11-04 12:46

Hi Clare,

When you're outside of a Price Tapestry directory, you can't require() common.php directly because it has special code inside it to work out where in the Price Tapestry folder you currently are; so instead you have to include the files individually as in the previous example.

The files that contain the library functions must only be included once, but config.php can be included as many times as you like because all it does is set the configuration variables.

Therefore, the above code should work just by including database.php and tapestry.php from one installation, and then the config from the site you want to query. You also need to require the HTML module directly rather than with an http:// address, for example:

 // don't include these if already included higher up in the script
 require("christmas-gifts-uk/includes/database.php");
 require("christmas-gifts-uk/includes/tapestry.php");
 // require the config file from the version you want
 require("christmas-gifts-uk/config.php");
 print javascript_focus("search.q");
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
  if (database_querySelect($sql,$rows))
  {
    $sqlNames = array();
    foreach($rows as $featured)
    {
      $sqlNames[] = "'".$featured["name"]."'";
    }
    $sqlIn = implode(",",$sqlNames);
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";
    database_querySelect($sql,$rows);
    $featured["products"] = $rows;
    foreach($featured["products"] as $k => $product)
    {
      if ($config_useRewrite)
      {
        $featured["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
        $featured["products"][$k]["reviewHREF"] = "review/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $featured["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
        $featured["products"][$k]["reviewHREF"] = "reviews.php?q=".urlencode($product["name"]);
      }
    }
  }
  if (isset($featured)) require("christmas-gifts-uk/html/featured.php");

Cheers,
David.

Submitted by clare on Sun, 2007-11-04 18:18

Yes thanks, thats working, much appreciated with it being Sunday as well :)