multi list / categories

2 posts by 2 authors in: Forums > CMS Builder
Last Post: October 8, 2013   (RSS)

By Daryl - October 8, 2013 - edited: October 9, 2013

Hi Rez,

If my understanding is right, you can list all the categories and all the projects in each category if no category is selected by looping through all the categories instead of projects and pull out the projects that are in that category.

Example:

<?php if (!$selectedCategory): ?>

// load all categories if no category is selected
$getCategoryRecords = mysql_select('categories');

// loop through each category
foreach ($getCategoryRecords  as $category){

  // load all the projects under this category
  list($projectRecords, $projectRecordsMetaData) = getRecords(array( 
  'tableName' => 'projects', 
  'where' => "category LIKE '%\t{$category['num']}\t%'",
  'perPage' => '7'
  )); 

  // if there's a project in this category, loop through the projects
  if ($projectRecords){
     foreach ($projectRecords as $projects) {
        // your code here
     }
  }

}

<?php endif ?>

If you're worried about your page lagging because of the nested loops above, we're only pulling out and looping through 7(?) projects per category so I don't think it will cause any significant lagging.
But if you have a really big list of categories and projects, what I would do is I will add a pagination with 5-10 categories per page. We might also want to consider the file size of the images for each projects that will be loaded to the page.

Hope this helps!

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com