Hi David,
I have an email sent to me when a user searches for a product on my site and ends up at noresults.php.
<?php
if ($q)
{
mail("info@example.com","No Results Alert","No results for ".$q);
}
?>
Is it possible to do something similar for "product not found" in products.php in case someone find an old link to a product or somethings up with my database?
else
{
$banner["h2"] .= "(".translate("product not found").")";
}
}
Thanks
Adrian
Hi David,
Thanks a million. Working great :)
Adrian
Hello David and Adrian
Great idea, where abouts should we put the above code?
Thanks
Mally
Hi Mally,
For the no results - the code goes straight into html/noresults.php (empty by default). For a product not found, search products.php for this code (line 58 in the distribution):
$banner["h2"] .= "(".translate("product not found").")";
...and then insert the email line immediately afterwards.
Cheers,
David.
hi david
sorry dont understand what you put where (sorry) can you post what code goes in what files please :)
thanks
paul
Hi Paul,
There's 2 different reasons for sending an email described above.
1. To receive an email when somebody enters a search that returns no results, look for the following code on line 151 of search.php:
$banner["h2"] .= "(".translate("no results found").")";
...and insert the following code on the next line:
mail("info@example.com","No Results Alert","No results for ".$q);
2. To receive an email when a visitor lands on a product page that no longer exists, look for the following code on line 58 of products.php:
$banner["h2"] .= "(".translate("product not found").")";
...and insert the following code on the next line:
mail("info@example.com","Product Not Found Alert","Product not found is ".$q);
Cheers,
David.
Hello David
I added this mod and have received alot of emails. The only way I've been working on them is too put them in subject order and then checking to see how many emails have got the same subject title so mention the same product name.
I'm not sure of the work involved, but would it be possible instead of sending emails, to add a table in the database which would show each subject, and the amount of times not found (to show popularity)
Then maybe a way to sort by popularity so I know which ones to work on first in priority? and then a way to delete that entry (once I've added the product)
I'm sure this involes a bit of work, what do you think?
Thanks Mally
Hi Mally,
If you use phpMyAdmin, this would be a very simple mod to implement, and then you could do all the management of the table (sorting, deleting) from within phpMyAdmin. If you create a table called "notfound" using the following SQL:
CREATE TABLE `notfound` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 255 ) NOT NULL ,
`count` VARCHAR( 11 ) NOT NULL
)
(if you use a $config_databaseTablePrefix, don't forget to add it to notfound)
To do this, just go to the SQL tab when browsing the Price Tapestry database in phpMyAdmin, and paste the SQL above into the text box, then click "Go".
Then, simply replace the line that sends email:
mail("info@example.com","Product Not Found Alert","Product not found is ".$q);
...with the following code:
$sql = "UPDATE `".$config_databaseTablePrefix."notfound` SET count=count+1 WHERE name='".database_safe($q)."'";
if (!database_queryModify($sql,$result))
{
$sql = "INSERT INTO `".$config_databaseTablePrefix."notfound` SET count=1, name='".database_safe($q)."'";
database_queryModify($sql,$result);
}
That should do the trick!
Cheers,
David.
Hello David
Thanks for giving this a go!
Not sure if the code needs changing slightly as I'm getting 2 entries listed, and the counts going up in 2's
Also, I'm getting the following error at the top of the page when I've inserted the code above..
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/magsub/public_html/includes/database.php on line 21
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/magsub/public_html/includes/database.php on line 26
Warning: Cannot modify header information - headers already sent by (output started at /home/magsub/public_html/includes/database.php:21) in /home/magsub/public_html/html/header.php on line 29
Hi Mally,
I just checked the code it it seems OK - could you email me your modified products.php and I'll check it out for you...
Cheers,
David.
Hello David
I've fixed it now, my error, thanks Mally
Hi Adrian,
Absolutely, in fact the product name (found or not) is also in the $q variable, so almost exactly the same code could be used at the point you identified:
else
{
mail("info@example.com","Product Not Found Alert","Product not found is ".$q);
$banner["h2"] .= "(".translate("product not found").")";
}
}
Cheers,
David.