List products for each category

7 posts by 3 authors in: Forums > CMS Builder
Last Post: September 28, 2012   (RSS)

Re: [justritedesign] List products for each category

By Mohaukla - September 28, 2012

Forgot my php top code:
// load records from 'categories'
list($categoriesRecords, $categoriesMetaData) = getRecords(array(
'tableName' => 'categories',
'loadUploads' => false,
'allowSearch' => false,
));

// load records from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'loadUploads' => false,
'allowSearch' => false,
));

$categories = mysql_select ('categories');
//make the array key the 'num' field
$categoriesSorted = array_groupBy($categories,'num');

Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Re: [justritedesign] List products for each category

By gregThomas - September 28, 2012

Hi Michael,

From the code you've posted it looks as if your not filtering the $productRecords in anyway.

I've just looked at this post (http://www.interactivetools.com/forum/gforum.cgi?post=95074#95074) to see how your products are linked to the categories, and I think this code below should do the trick:

<div class="left">
<ul><?php foreach ($categoriesRecords as $category): ?>
<li>
<a href="<?php echo $category['_link'] ?>"><?php echo htmlencode($category['title']) ?></a>
<ul><?php foreach ($productsRecords as $record): ?>
<?php if(in_array($category['num'], $subRecord[categories:values])): ?>
<li>
<a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['name']) ?></a>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
</li>
<?php endforeach ?>
</ul>
</div>




Let me know if this doesn't work.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] List products for each category

By Mohaukla - September 28, 2012 - edited: September 28, 2012

NOTE: I changed part of your code Here:
<?php if(in_array($category['num'], $subRecord[categories:values])): ?>
to:
<?php if(in_array($category['num'], $subRecord['categories:values'])): ?>

That did not work and it breaks the category link that passes to the category page

Here is the site map page:
http://2tinker.com.r15.millsys.org/sitemap.php

The links to the categories now do not carry the value to the category page (click any category to see what I mean)

The products are showing this error:
Notice: Undefined variable: subRecord in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137 Warning: in_array() expects parameter 2 to be array, null given in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137
Notice: Undefined variable: subRecord in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137 Warning: in_array() expects parameter 2 to be array, null given in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137
Notice: Undefined variable: subRecord in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137 Warning: in_array() expects parameter 2 to be array, null given in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137
Notice: Undefined variable: subRecord in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137 Warning: in_array() expects parameter 2 to be array, null given in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137
Notice: Undefined variable: subRecord in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137 Warning: in_array() expects parameter 2 to be array, null given in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137
Notice: Undefined variable: subRecord in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137 Warning: in_array() expects parameter 2 to be array, null given in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137
Notice: Undefined variable: subRecord in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137 Warning: in_array() expects parameter 2 to be array, null given in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137
Notice: Undefined variable: subRecord in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137 Warning: in_array() expects parameter 2 to be array, null given in D:\HostingSpaces\2tinker\2tinker.com\wwwroot\sitemap.php on line 137

Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Re: [justritedesign] List products for each category

By gregThomas - September 28, 2012

Sorry about that, I forgot to rename a variable after testing the code on my machine. You should just need to rename the variable highlighted in blue:

<div class="left">
<ul><?php foreach ($categoriesRecords as $category): ?>
<li>
<a href="<?php echo $category['_link'] ?>"><?php echo htmlencode($category['title']) ?></a>
<ul><?php foreach ($productsRecords as $record): ?>
<?php if(in_array($category['num'], $record['categories:values'])): ?>
<li>
<a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['name']) ?></a>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
</li>
<?php endforeach ?>
</ul>
</div>


Hopefully it should work this time!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] List products for each category

By Mohaukla - September 28, 2012

Sorry that did not work

Maybe I am not setting it up right...

<?php if(in_array($category['num'], $record['name'])): ?>
Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Re: [justritedesign] List products for each category

By Jason - September 28, 2012

Hi Michael,

Try this:

<?php if(in_array($category['num'], $record['categories:values'])): ?>

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/