You are here:  » Cateogries Multiple PT setup Questions

Support Forum



Cateogries Multiple PT setup Questions

Submitted by Andrewc on Fri, 2009-06-19 10:28 in

I'm going to be setting up multiple PT installations according to my needed categories.
Then use the Single search box + drop down.

My questions:

  • Is it recommended to have each installation use its own database or can I use a single DB and just change the table prefix?
  • Would it be possible on the Global search box to search through All Categories?

all for now..

Submitted by support on Fri, 2009-06-19 10:42

Hi Andrew,

A single database with a different table for each installation would be fine - a MySQL table is essentially just a file on disk, so it won't make any difference to load etc. than if you used multiple databases - and in fact may even be slightly more efficient because as users of your site browse different installations MySQL won't have to keep re-loading the database "meta data".

Theoretically it would be possible to write a top-level search script that would search the multiple installations, perhaps just giving links to each category into the full search results, e.g.

Results can be found in the following cateogries;

Electronics (19)
Home (4)

(with the category names being a link to /category/search.php?q=Keywords etc.)

An optimisation of course would be that if results are only found in one category you could redirect directly to that category with a 302 header. Let me know if you need any pointers for this...

Cheers,
David.

Submitted by daem0n on Sun, 2009-06-21 03:06

Hey David!

Can you give us some pointers on this? I for one would love to try to work something like this into my PT installation :)

Thanks a lot, -Joe

Submitted by support on Mon, 2009-06-22 07:22

Hello Joe,

Sure. Can you describe your multi-category set-up? Is it exactly as described in this thread where you have installations in sub-directories, for example:

/electronics/
/home/
/clothing/

etc.?

Cheers,
David.

Submitted by daem0n on Mon, 2009-06-22 07:29

Hi David,

Thanks for the reply! Yes, the categories are exactly like that...in sub-directories :)

Thanks, -Joe

Submitted by support on Mon, 2009-06-22 07:49

Hi Joe,

OK - i'll set-up the scenario on my test server and put something together... please bear with me as I've quite badly cut my right index finger and it's hurting quite a bit to type at the moment...!

Cheers,
David.

Submitted by daem0n on Mon, 2009-06-22 08:07

Yikes! Hope you're ok, no rush on this stuff...health is always more important ;)

Thanks a lot, -Joe

Submitted by daem0n on Wed, 2009-06-24 22:53

Hi David,

Did you find any possibilities of this method working? I'm thinking it may just require modifications to the config file?...or is there more to it? Let me know!

Thanks, -Joe

Submitted by support on Thu, 2009-06-25 08:51

Hi Joe,

Sure - i've just had a go at this, and seems to work quite nicely. Start by testing this in a standalone script in your toplevel directory before incorporating with your main site (but it should just be a case of copying the code into your main index page).

searchAll.php

<?php
  $sites 
= array();
  
$sites["Category 1"] = "category1folder";
  
$sites["Category 2"] = "category2folder";
  print 
"<form method='GET'>";
  print 
"<input type='text' name='q' value='".htmlentities($_GET["q"])."' /> ";
  print 
"<input type='submit' value='Search' />";
  print 
"</form>";    
  if (
$_GET["q"])
  {
    
$results = array();
    
$first TRUE;
    foreach(
$sites as $category => $directory)
    {
      require(
$directory."/config.php");
      if (
$first)
      {
        require(
$directory."/includes/database.php");
        
$first FALSE;
      }
      
$sql "SELECT COUNT(*) AS numResults FROM `".$config_databaseTablePrefix."products` WHERE search_name LIKE '%".database_safe($_GET["q"])."%'";
      
database_querySelect($sql,$rows);
      if (
$rows[0]["numResults"])
      {
        
$results[$category] = $rows[0]["numResults"];
      }
    }      
    if (
count($results))
    {
      print 
"<ul>";
      foreach(
$results as $category => $numResults)
      {
        print 
"<li><a href='".$sites[$category]."/search.php?q=".urlencode($_GET["q"])."'>".$category."</a> (".$numResults.")</li>";
      }
      print 
"</ul>";
    }
    else
    {
      print 
"<p>No results found.</p>";
    }
  }
?>

Simply edit the $sites array and add / remove entries as required for each of your category installations, with the key being the category name as you want it displayed, and the value being the name of the sub-directory of that installation, for example:

  $sites = array();
  $sites["Electronics"] = "electronics";
  $sites["Home and Garden"] = "home";

etc. Hope this helps!

Cheers,
David.

Submitted by cq on Thu, 2009-06-25 09:16

Hi David,

I am doing a testing on this. I copy the code and create a searchall.php file and put it under html. Then in index.php page add the file. When do search nothing comes out. Hv also made the changes as mentioned. Wonder if this could work.

thanks
jack

Submitted by cq on Thu, 2009-06-25 09:20

Hi David,

I found an error below. Wonder what thats mean.

[25-Jun-2009 17:08:47] PHP Fatal error: require() [function.require]: Failed opening required 'electronics/config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxx/public_html/xxx.com/html/searchall.php on line 36

cheers
jack

Submitted by cq on Thu, 2009-06-25 09:24

Hi David,

I found another error.

[25-Jun-2009 17:16:35] PHP Fatal error: Cannot redeclare database_queryselect() in /home/xxxx/public_html/xxx.com/electronics/includes/database.php on line 3

Wonder what that means.

thanks
jack

Submitted by support on Thu, 2009-06-25 09:34

Hello Jack,

Does your top level also have a Price Tapestry installation? That would cause the second problem - but i'm not sure about the first. Is there definitely an installation at:

/electronics/

...on your site? In which case, can you try browsing to electronics/config.php to check the the file exists exactly as per the first error...?

Cheers,
David.

Submitted by cq on Thu, 2009-06-25 11:35

Hello David

Yes. I installed on main domain. If removed it how do i maintain the same look and feel. If I just put index.php file on main how the rest required html files will work.

thanks
jack

Submitted by support on Thu, 2009-06-25 11:47

Hi,

Could you email me your index.php that you added the above code to and I'll take a look! It doesn't seem to be handling $_GET["q"] - but I also notice that you are bringing in other elements of Price Tapestry into the home page so there may be conflicts there...

Cheers,
David.

Submitted by cq on Thu, 2009-06-25 15:45

Hi David,

Thank you very much. It is working well.

cheers
jack

Submitted by cq on Thu, 2009-06-25 18:09

Hi David,

I did some testing on the new script. Now wonder if it works the same in the subcategories as well.

Testing done on another search box with dropdown. If you take a look at the dropdown search box in electronic category, when do another search it still remain there. It won't jump to a new product search or jump to new product search for another category from the dropdown ie. watches.

Is there a way to fix this.

thanks
jack

Submitted by daem0n on Fri, 2009-06-26 00:47

Hi David,

This is great, thanks a lot! Quick question - if I want to migrate all of my databases to the same database...can I just migrate them to different tables within the same database and then use:

$config_databaseServer = "localhost"; (same on all installs)
$config_databaseUsername = "username"; (same on all installs)
$config_databasePassword = "password"; (same on all installs)
$config_databaseName = "database"; (same on all installs)

$config_databaseTablePrefix = "categoryName"; (different depending on installation)

Will these settings work for multiple installations within the same database?

Thanks a lot for everything! -Joe

Submitted by support on Fri, 2009-06-26 10:59

Hi all,

Jack - could you email me a link to the page showing the drop-down, and the relevant PHP files - for example index.php or whatever PHP file contains the drop down. It is probably just a case of adding a hidden field.

Joe - that will work fine!

Cheers,
David.

Submitted by cq on Sat, 2009-07-04 09:22

Hello David,

I have managed to solve the problem. For the below script, if i place it in subinstallion index.php it will work. However, how do i place this script in main installation page where people can view these products from the subinstallation site.

 print "<table width='728' border='1' cellspacing='0' cellpadding='2'>";
 print "<tr width='182'>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE merchant = 'Discount Watch Store' ORDER BY RAND() LIMIT 4";
  database_querySelect($sql,$products);
  foreach($products as $product)
  {
  if ($product["image_url"])
  {
    $productHREF = $config_baseHREF."product/".str_replace(" ","-",$product["name"]).".html";
    print "<td align='center' width='182'>";
print "</br>";
    print "<a href='".$productHREF."' ><img width='120' height='120' border=0 src='".$product["image_url"]."' alt='".$product["name"] ."' /></a><br>";
 print "</br>";
    print "<font size=1> <a href='".$productHREF."'> ".$product["name"]."</a><br>";
    print "</br>";
    print $config_currencyHTML.$product["price"]." <br /></font>\n";
 print "</br>";
?>
<?php
    print "</td>";
  }
  else
  {
    print "<td>&nbsp;</td>";
  }
}
print "</tr>";
print "</table>";

I assume this will work for category and brand as well

thanks
jack

Submitted by support on Sat, 2009-07-04 10:23

Hello Jack,

It should work fine at the top level, as $config_baseHREF will contain the name of the folder in which it is installed.

Therefore, the only change you would need to make would be to the include files, as they would need the full path, and also be included separately rather than via common.php. For example, in your top level script, instead of:

  require("includes/common.php");

...you would need:

  require("folder/config.php");
  require("folder/includes/database.php");

(where "folder" is the name of the sub-directory in which the script is installed)

Cheers,
David.

Submitted by cq on Mon, 2009-07-06 09:58

Hello David,

I don't quite understand. Let say my subinstallation is www.abcde.com/electronics. So in the main domain ie. www.abcde.com, I have to include the below two files and remove require("include/common.php"); from the index.php of www.abcde.com?

require("electronics/config.php");
require("electronics/includes/database.php");

If that is correct, apart from the above, what else do I need to do changes?

thanks
jack

Submitted by support on Mon, 2009-07-06 11:25

Hello Jack,

That looks OK. The reason that you can't simply require("electronics/includes/common.php") directly is because common.php looks to see which folder it is in (when included from the Price Tapestry root or /admin/ folder) and uses an appropriate path to include the other files.

Therefore, when outside that Price Tapestry tree, it's necessary to first include config.php directly, and then any other include files required by your script - which in the case of the code above should just be database.php.

If you're not sure why it's not working, if you could email me your script and a link to the site where it is running i'll check it over for you!

Cheers,
David.

Submitted by Rocket32 on Tue, 2009-07-07 04:12

Hello David,

How could I implement this same tactic on different domains instead of different categories within a domain?
What I mean is if I have a database with many different merchants and I add another domain using the same database and selecting only certain merchants used from that database. Would this require a new installation of Price Tapestry to use same database but not all the same merchants only 1 or some? I would like to be able to pick which Merchant to import into the new domain's table or site.

Submitted by support on Tue, 2009-07-07 08:29

Hi,

Whilst different domains can easily share the same database if you want the same merchants all included; if you only want a selection it would be inefficient to have to restrict all the SQL to the required merchants.

Instead, what I would recommend is separate installations, but sharing a common /feeds/ folder. This would prevent you from having to manage the feeds in multiple locations - you would then simply register and import only the merchants required on that installation.

To do this, you'd simply need to replace the relative path to the feeds folder:

../feeds/

...to the absolute path on your server, for example:

/home/username/domains/example.com/feeds/

...in the following files:

admin/feeds_extras.php
admin/feeds_register_step1.php
admin/feeds_register_step2.php
admin/index.php
includes/admin.php
scripts/import.php

Cheers,
David.

Submitted by cq on Tue, 2009-07-07 08:52

Hello David,

Thank you so very much for your super fast reply. It is working already.

cheers
jack

Submitted by daem0n on Thu, 2009-09-24 02:25

Hi David,

Quick revisit to this subject. I'm trying to create a page off of another page that shows these search results. So, say you're on the main page and you submit the search. I want the script to load an "Advanced Search" page with the returned results instead of what it's currently doing which is just posting the results below the search form. From this "Advanced Search" page, people could click on the specific category, etc and then go directly to a search results page. I'm trying to figure out what I need to modify.

Basically, I want to put:

<?php
  $sites 
= array();
  
$sites["Category 1"] = "category1folder";
  
$sites["Category 2"] = "category2folder";
  print 
"<form method='GET'>";
  print 
"<input type='text' name='q' value='".htmlentities($_GET["q"])."' /> ";
  print 
"<input type='submit' value='Search' />";
  print 
"</form>";
?>

...into one page

and then I want this part:

<?php
  
if ($_GET["q"])
  {
    
$results = array();
    
$first TRUE;
    foreach(
$sites as $category => $directory)
    {
      require(
$directory."/config.php");
      if (
$first)
      {
        require(
$directory."/includes/database.php");
        
$first FALSE;
      }
      
$sql "SELECT COUNT(*) AS numResults FROM `".$config_databaseTablePrefix."products` WHERE search_name LIKE '%".database_safe($_GET["q"])."%'";
      
database_querySelect($sql,$rows);
      if (
$rows[0]["numResults"])
      {
        
$results[$category] = $rows[0]["numResults"];
      }
    }
    if (
count($results))
    {
      print 
"<ul>";
      foreach(
$results as $category => $numResults)
      {
        print 
"<li><a href='".$sites[$category]."/search.php?q=".urlencode($_GET["q"])."'>".$category."</a> (".$numResults.")</li>";
      }
      print 
"</ul>";
    }
    else
    {
      print 
"<p>No results found.</p>";
    }
  }
?>

...to show-up in a different page with other information.

Is that possible? I think I just have to change the "action" but I have no idea.

Thanks for any help as always!!
-Joe

Submitted by support on Thu, 2009-09-24 08:28

Hi Joe,

Almost... Changing the action is the main thing; but you will also have to move the
$sites array into the second script (whatever the action page is). So in your first
page you would just have:

<?php
  
print "<form method='GET' action='advancedsearch.php'>";
  print 
"<input type='text' name='q' value='".htmlentities($_GET["q"])."' /> ";
  print 
"<input type='submit' value='Search' />";
  print 
"</form>";
?>

And then at the top of advancedsearch.php (inside the opening PHP tag),
as well as the rest of the handler code you would need to add the
$sites array; e.g.

  $sites = array();
  $sites["Category 1"] = "category1folder";
  $sites["Category 2"] = "category2folder";

Hope this helps!

Cheers,
David.

Submitted by daem0n on Tue, 2009-09-29 07:39

Thanks David! That helped a lot! One more issue is that (since before) the search results (count) has not been accurate. It usually lists about 75 matches but then when you go into that category, there are only about 5 actual matches. Another category lists 1488 matches but when you go to that category it really only has about 840 matches.

I'm pretty sure it's because of the modified statements in the code, such as this in search.php instead of above in this thread:

<?php
          
foreach($words as $word)
          {
            
$wheres[] = "search_name LIKE '%".database_safe($word)."%'";
          }
          
$where implode(" AND ",$wheres);
          
$sql "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE ".$where." GROUP BY name";
          
$sqlResultCount "SELECT COUNT(DISTINCT(name)) as resultcount FROM `".$config_databaseTablePrefix."products` WHERE ".$where;
          
$orderBySelection $orderByDefault;
?>

...or maybe because I have the sku mod? I'm just confused as to where I should look. Is the "correct" formula and query in the search.php or products.php?

Thanks for any help!! -Joe

Submitted by support on Tue, 2009-09-29 08:24

Hello Joe,

The first version is just counting exact matches for the entire query and not
GROUPing by name; whereas the second version (in search.php) is using an AND
expression where individual words can be anywhere in the product name;

What I would do is replicate the search.php count in the outside version as follows;

<?php
  
if ($_GET["q"])
  {
    
$words explode(" ",$q);
    foreach(
$words as $word)
    {
      
$wheres[] = "search_name LIKE '%".database_safe($word)."%'";
    }
    
$where implode(" AND ",$wheres);
    
$results = array();
    
$first TRUE;
    foreach(
$sites as $category => $directory)
    {
      require(
$directory."/config.php");
      if (
$first)
      {
        require(
$directory."/includes/database.php");
        
$first FALSE;
      }
      
$sql "SELECT COUNT(DISTINCT(name)) AS numResults FROM `".$config_databaseTablePrefix."products` WHERE ".$where." GROUP BY name";
      
database_querySelect($sql,$rows);
      if (
$rows[0]["numResults"])
      {
        
$results[$category] = $rows[0]["numResults"];
      }
    }
    if (
count($results))
    {
      print 
"<ul>";
      foreach(
$results as $category => $numResults)
      {
        print 
"<li><a href='".$sites[$category]."/search.php?q=".urlencode($_GET["q"])."'>".$category."</a> (".$numResults.")</li>";
      }
      print 
"</ul>";
    }
    else
    {
      print 
"<p>No results found.</p>";
    }
  }
?>

Hope this helps!

Cheers,
David.

Submitted by daem0n on Tue, 2009-09-29 09:44

ok last question for a while I hope haha!

I implemented this and it looks like it could work but now I'm having issues because this search page is in a main directory and not a "category" sub-directory. So the page is having problems on this line:

<?php
       $wheres
[] = "search_name LIKE '%".database_safe($word)."%'";  
?>

because "database_safe" isn't defined. I can include "/includes/common.php" but that line would come after the above...because I'd have to specify one of the category sub-sites.

What do you suggest? I don't mind moving some files around/copying, etc. if that's the best method. What do you think?

Thanks again!!
-Joe

Submitted by support on Tue, 2009-09-29 10:37

Hello Joe,

My apologies, i'd overlooked that. Just use....

       $wheres[] = "search_name LIKE '%".mysql_escape_string($word)."%'";

...which will do the same thing without needing the include...

Cheers,
David.

Submitted by daem0n on Tue, 2009-09-29 10:47

Great, thanks a lot as always David! I will try it later on today :)

-Joe

Submitted by daem0n on Wed, 2009-09-30 05:45

Well close, but no cigar! Now it lists only 1 result per category. I know in the products.php code I have it counting properly but it's a loop (because of the sku) code/modification. I tried modifying this code a bit but it isn't working out. If I get rid of the "GROUP BY name" it lists astronomical amounts of matches per category which isn't right either. Any other ideas? I think I'm lost now lol

Thanks David :)
-Joe

Submitted by support on Wed, 2009-09-30 08:02

Hi Joe,

Could you perhaps email me the whole script and I'll take a look for you!

Cheers,
David.