Record counter from another section list menu type

7 posts by 2 authors in: Forums > CMS Builder
Last Post: November 18, 2010   (RSS)

By ht1080z - November 18, 2010

Hi,

I created a multi menu type section (used_items) where one of the fields is list field type (item) and selected from another category menu section (cat_items).
I'm trying to display in list page every records from cat_items & count and display how many records are created in the used_items with each cat_items.

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


// load viewer library
$libraryPath = 'bcmAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/vournas/public_html/','','../','../../','../../../');
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($cat_itemsRecords, $cat_itemsMetaData) = getRecords(array(
'tableName' => 'cat_items',
'loadUploads' => '0',
'allowSearch' => '0',
));

// load records
list($used_itemsRecords, $used_itemsMetaData) = getRecords(array(
'tableName' => 'used_items',
'loadUploads' => '0',
'allowSearch' => '0',
));

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<?php foreach ($cat_itemsRecords as $record): ?>
<li><a href="#"><?php echo $record['name'] ?>&nbsp;(x)</a></li>
<?php endforeach ?>

</body>
</html>


The (x) is the counter holder of each category.
Can anybody advise how i can count these records in the foreach for every category.

Thank you in advance,

Re: [Jason] Record counter from another section list menu type

By ht1080z - November 18, 2010

Hi Jason,

Thanks for your reply.
I am little bit confused with the additional php script.
let me show you how i implemented:

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


// load viewer library
$libraryPath = 'bcmAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/vournas/public_html/','','../','../../','../../../');
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($cat_itemsRecords, $cat_itemsMetaData) = getRecords(array(
'tableName' => 'cat_items',
'loadUploads' => '0',
'allowSearch' => '0',
));

// load records
list($used_itemsRecords, $used_itemsMetaData) = getRecords(array(
'tableName' => 'used_items',
'loadUploads' => '0',
'allowSearch' => '0',
));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Vournas Test</title>
</head>
<body>

<?php $cat_count=array();
foreach($used_itemsRecords as $used_item){
@$cat_count[$used_item['item']]++;
}
?>
<?php foreach ($cat_itemsRecords as $record): ?>
<li><a href="#"><?php echo $record['name'] ?>&nbsp;(<?php echo intval(@$cat_count[$record['item']];?>)</a></li>
<?php endforeach ?>

</body>
</html>


after this: Parse error: syntax error, unexpected ';' in /home/vournas/public_html/test.php on line 155
(where is the <?php echo intval(@$cat_count[$record['item']];?>)

i changed the 'num' to 'item'

in the attached pictures you can see how the tables are builded.
in the 'cat_items' table i use and list the 'name' field
in the 'used items' the 'item' field used and the record selected from the above cat_items/name

Side by every listed cat_item need to display how many times is found in the 'used_items' table 'item' field.

the below link show before i make the changes (is in greek) and display all records from the cat_items.
http://vournas.gr/test.php

i hope these attachments help somehow.

Please advise,
Attachments:

used_items.jpg 94K

cat_items.jpg 94K

Re: [ht1080z] Record counter from another section list menu type

By Jason - November 18, 2010

Hi,

The problem is there is a missing semicolon ";" after you output the record's name. Try changing it to this:

<li><a href="#"><?php echo $record['name']; ?>&nbsp;(<?php echo intval(@$cat_count[$record['item']];?>)</a></li>

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] Record counter from another section list menu type

By ht1080z - November 18, 2010

Jason,

i corrected the syntax but got the same Parse error in the same line.
Parse error: syntax error, unexpected ';' in /home/vournas/public_html/test.php on line 155

<li><a href="#"><?php echo $record['name']; ?>(<?php echo intval(@$cat_count[$record['item']]; ?>)</a></li>

Can you please recheck my previous reply, think i messed up the script, also i attached some screenshot of the CMSB tables.

Thank you,

Re: [ht1080z] Record counter from another section list menu type

By Jason - November 18, 2010

Hi,

Oops, we forgot a closing bracket. Give this a try:

<li><a href="#"><?php echo $record['name']; ?>(<?php echo intval(@$cat_count[$record['item']]); ?>)</a></li>

That should take care of that error for you.
---------------------------------------------------
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] Record counter from another section list menu type

By ht1080z - November 18, 2010

Jason,

I correct the syntax error and changed the $record['item'] to $record['num'] and it works!

Thank you for your support on this! [:)]