Suggested Related Product

19 posts by 5 authors in: Forums > CMS Builder
Last Post: November 12, 2010   (RSS)

Re: [Jason] Suggested Related Product

Thanks for the insights, Jason.

I'll give it a try and see how far I can get.

Jerry

(I'm sure that you'll be hearing from me again on this)
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [chris] Suggested Related Product

Hi Chris,

I know it’s been a while, but I’m having a problem implementing the code you suggested above.

Dreamweaver indicates that there’s a syntax error and I could use your help.

Thanks,

Jerry Kornbluth

Here’s the code I’m using.
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/hsphere/local/home/gkornblu/thecmsbcookbook.com/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$productsRecord = @$productsRecords[0]; // get first record

// show error message if no matching record is found
if (!$productsRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

$categories = explode("\t", trim($productRecord['categories']));

$where = "";

//error on next line
foreach ($category in $categories) {
if ($where) { $where .= " OR "; }
$where .= "categories LIKE '%\t" . mysql_escape($category) . "\t%'"
}
//error on preceding line

if ($where) {
list($relatedProducts,) = getRecords(array(
'tableName' => 'products',
'where' => $where,
'limit' => '10',


));
}
else {
$relatedProducts = array();
}

?>
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Chris - November 11, 2010

Hi Jerry,

What's the exact error message you're getting?
All the best,
Chris

Re: [chris] Suggested Related Product

Thanks for getting back to me Chris,

There's a highlight before the 2 lines mentioned and the Dreamweaver CS5 message that there's a syntax error on line 31 and the code may not work until you fix the error.

Screen capture attached

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

error_002.jpg 388K

By Chris - November 11, 2010

Oops. Someone's been writing too much JavaScript / AS3 / Python!

foreach ($category in $categories) {

... should be:

foreach ($categories as $category) {

I hope this helps! :)
All the best,
Chris

Re: [chris] Suggested Related Product

By gkornbluth - November 11, 2010 - edited: November 11, 2010

Thanks Chris,

Now I'm down to only one error after the brace.

Jerry

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/hsphere/local/home/gkornblu/thecmsbcookbook.com/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$productsRecord = @$productsRecords[0]; // get first record

// show error message if no matching record is found
if (!$productsRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

$categories = explode("\t", trim($productRecord['categories']));

$where = "";


foreach ($categories as $category){
if ($where) { $where .= " OR "; }
$where .= "categories LIKE '%\t" . mysql_escape($category) . "\t%'"
}
//error on preceding line

if ($where) {
list($relatedProducts,) = getRecords(array(
'tableName' => 'products',
'where' => $where,
'limit' => '10',


));
}
else {
$relatedProducts = array();
}

?>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Jason - November 12, 2010

Hi Jerry,

It looks like you're missing a semicolon at the end of that line. Try this:

foreach ($categories as $category){
if ($where) { $where .= " OR "; }
$where .= "categories LIKE '%\t" . mysql_escape($category) . "\t%'";
}


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Suggested Related Product

Right you are.

Thanks Jason
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php