List products for each category
7 posts by 3 authors in: Forums > CMS Builder
Last Post: September 28, 2012 (RSS)
By Mohaukla - September 27, 2012 - edited: September 28, 2012
<div class="left">
<ul><?php foreach ($categoriesRecords as $category): ?>
<li>
<a href = "category.php?categories=<?php echo $category['num'];?>"><?php echo $category['title'];?></a>
<ul><?php foreach ($productsRecords as $record): ?>
<li>
<a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['name']) ?></a>
</li>
<?php endforeach ?>
</ul>
</li>
<?php endforeach ?>
</ul>
</div>
Thanks in advance,
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
// 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');
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
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!
PHP Programmer - interactivetools.com
Re: [greg] List products for each category
By Mohaukla - September 28, 2012 - edited: September 28, 2012
<?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
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
<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!
PHP Programmer - interactivetools.com
Re: [greg] List products for each category
Maybe I am not setting it up right...
<?php if(in_array($category['num'], $record['name'])): ?>
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
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/