Hi David,
I'm trying to add a script to achieve showing price comparisons on a different sub-domain web page You covered how to do this in http://www.pricetapestry.com/node/2274, but I can't seem to get it working.
My site is www.compare-pushchairs.co.uk
I have made a sub-directory on the same server "pricecheck.compare-pushchairs.co.uk" and added the following script to index.html in the folder "pricecheck" within htdocs:
<?php
$common_path = "/htdocs";
$_GET["q"] = "Baby Jogger Freedom";
require($common_path."pricesExternal.php");
?>
pricesExternal.php is in place in the htdocs folder (where PriceTapestry is installed)
Could you tell me where I am going wrong?
Many thanks,
shabbysheep
Thanks David, that gives me
\\NAS42ENT\domains\c\compare-pushchairs.co.uk\user\htdocs\
added as:
<?php
$common_path = "\\NAS42ENT\domains\c\compare-pushchairs.co.uk\user\htdocs\";
$_GET["q"] = "Baby Jogger Freedom";
require($common_path."pricesExternal.php");
?>
But I still get no results. Should I be using all the displayed path?
Thanks,
shabbysheep
Hi!
I see the problem! A back-slash is the escape character within a PHP string; so a Windows OS URL would have to be specified using double-back-slashes; for example:
$common_path = "\\\\NAS42ENT\\domains\\c\\compare-pushchairs.co.uk\\user\\htdocs\\";
That should do the trick...
Cheers,
David.
Hi,
Are you getting anything displayed at all - even an error message?
I would try this as a test:
<?php
$common_path = "\\\\NAS42ENT\\domains\\c\\compare-pushchairs.co.uk\\user\\htdocs\\";
$_GET["q"] = "Baby Jogger Freedom";
if (!file_exists($common_path."pricesExternal.php"))
{
print $common_path."priceExternal.php not visible from here";
}
?>
If the message is displayed, this might indicate a permissions problem; in that the location of the calling script does not have read access to the location of pricesExternal.php...
Cheers,
David.
Hi,
Sure - email across anything you want me to have a look at and i'll check it over for you...
Cheers,
David.
Hello David, I have emailed a page source read out to you, hope you are able to spot the problem.
Regards,
shabbysheep
Hi David,
I'm also trying to use this feature but am having similar problems. I am also on a Windows/IIS platform - wonder if this is the issue? Anyway, the pricesExternal.php file is being found and read, and am guessing that the includes therein are being processed OK as there are no 'undefined function' errors when using tapestry_normalise or database_safe etc. It seems that no records are being returned by the query, i.e. $numRows is null. The query is fine though as if it is run separately it returns records.
Any ideas??
Cheers.
Keeop
Hi Keeop,
Could you perhaps email me a link to your site and the URL to and the source code behind the file in which you have placed the calling code and i'll check it out for you!
Cheers,
David.
As a follow up, it seems to be the global variables. e.g. the DB name is fine before the database.php include but within the include the value is lost. I've also pasted the DB functions directly in the external.php file and within the query_select function the DB values are lost. Bizarre! These variables are behaving fine when the web site which hosts them is calling them, but not on the site that I'm trying to pull prices in to. Is there a limted scope on globals?
Cheers.
Keeop
Hi Keeop,
Are you using the latest version of the external files from this thread? This issue has come up before and I modified the files so that the configuration variables are declared global before setting them. It could be the case you see that where the code is called from within your other script that you are already within a function; and therefore not in the global scope...
Cheers,
David.
Hi David,
No, I was using an earlier version I guess but I changed it pretty much to how the new version is! Anyway, I think I have found the problem. It's nothing to do with the PT code, which I didn't think it was, but to do with how the code that calls it is working.
For this Joomla site I'm working on, and the other Aff script I have been using, it seems that the database is connected to first thing in the PHP but then all new DB actions refer to a handle of it rather than the DB itself - something like this anyway! The bottom line being that if I explicitly reference a different DB, like in the PT scripts, any following DB calls from the Joomla code then also reference the PT DB. I need to work out how to re-establish the connection to the Joomla DB after I have finished with the PT DB for it to all work properly, or access the PT DB using 'Joomla methods' so it all doesn't get muddled up.
Probably haven't explained it all that clearly but I'm not entirely sure what I'm talking about suffice to say I'll turn my attentions to the Joomla forums to try and find an answer as it's not a PT issue.
Thanks though!
Keeop
Hi Keeop,
You could try forcing Price Tapestry to make a new database connection; which might leave Joomla free to reuse its original connection. To do this, in includes/database.php, replace line 13, currently:
$link = @mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);
...with:
$link = @mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword,TRUE);
The TRUE parameter forces a new link to be created, which might help...!
Cheers,
David.
Hi David,
Fantastic - you da man!
Thanks for that, it all now works. Just one question - does this cause any sort of performance hit? Just wondering whether to have a separate connection string in the priceExternal.php and leave the database.php connection as-is?
Thanks again.
Keeop
Hi Keeop,
It might be worthwhile doing that.
I would just make a copy of database.php and call it database2.php with the create new link mod as described above; then just edit pricesExternal.php to require("includes/database2.php") instead...
Cheers,
David.
Hi,
There is almost certainly more to the path than htdocs; as this directory itself is not normally at the top level. You can use the whereami.php script from this thread to help you work out what the value of $common_path should be - create the following file in your Price Tapestry installation folder (the same place as pricesExternal.php):
whereami.php
<?php
$path = $_SERVER["SCRIPT_FILENAME"];
$path = str_replace("whereami.php","",$path);
print $path;
?>
...and then browse to it. Whatever is displayed by the script, enter that as $common_path and it should do the trick!
Cheers,
David.