This topic is locked
[SOLVED]

 Menu Item Advanced

3/28/2011 2:36:59 PM
PHPRunner General questions
cyberjas2001 author

I have created the following PHP Code for my Menu Item - Modify:
if($menuItem->getLinkType() == 'Internal')

{

global $tables_data;

$table=$menuItem->getTable();

include_once(getabspath("include/".GetTableURL($table)."_settings.php"));

$table=GetOriginalTableName($table);
if (($table)==("container"))

{

$rs=CustomQuery("select count() as c1 from container where status='Active'" );

$data = db_fetch_array($rs);

$menuItem->setTitle($menuItem->getTitle() . " (". $data["c1"] . ")");

}
else

{

$rs=CustomQuery("select count(
) as c1 from " . AddTableWrappers($table));

$data = db_fetch_array($rs);

$menuItem->setTitle($menuItem->getTitle() . " (". $data["c1"] . ")");

}
}

return true;
The result shows:
Main Menu

Login (4)

Company (107)

Chassis (11)

Steamship (25)

Container (44)

Active Containers (44)

Closed Containers (44)

Container Report (44)
It works flawlessly, but i have a problem, i want to show the total of some custom views i created, these are "Active Containers" and "Closed Containers" which are custom views of my table "container". If any container has it (status = active) has to be count in the "Active Containers View" and if is (status = closed) will be count in the "Closed Containers View". The problem is that i cant call my custom view so i can run my conditional sentence IF. For Example:
if (($table)==("Active Containers"))

{

$rs=CustomQuery("select count() as c1 from . AddTableWrappers($table) );

$data = db_fetch_array($rs);

$menuItem->setTitle($menuItem->getTitle() . " (". $data["c1"] . ")");

}

elseif (($table)==("Closed Containers"))

{

$rs=CustomQuery("select count(
) as c1 from . AddTableWrappers($table) );

$data = db_fetch_array($rs);

$menuItem->setTitle($menuItem->getTitle() . " (". $data["c1"] . ")");

}
I need help, thanks!!!

Sergey Kornilov admin 3/28/2011

GetOriginalTableName($table) function returns database table name by custom view name. You may want to restructure your code a little bit.

  1. Drop the following line:

$table=GetOriginalTableName($table);


2. Modify section that works with custom views:

if (($table)==("Active Containers"))

{

$rs=CustomQuery("select count(*) as c1 from container");

$data = db_fetch_array($rs);

$menuItem->setTitle($menuItem->getTitle() . " (". $data["c1"] . ")");

}

elseif (($table)==("Closed Containers"))

{

$rs=CustomQuery("select count(*) as c1 from container");

$data = db_fetch_array($rs);

$menuItem->setTitle($menuItem->getTitle() . " (". $data["c1"] . ")");

}
cyberjas2001 author 3/28/2011



GetOriginalTableName($table) function returns database table name by custom view name. You may want to restructure your code a little bit.

  1. Drop the following line:

$table=GetOriginalTableName($table);


2. Modify section that works with custom views:

if (($table)==("Active Containers"))

{

$rs=CustomQuery("select count(*) as c1 from container");

$data = db_fetch_array($rs);

$menuItem->setTitle($menuItem->getTitle() . " (". $data["c1"] . ")");

}

elseif (($table)==("Closed Containers"))

{

$rs=CustomQuery("select count(*) as c1 from container");

$data = db_fetch_array($rs);

$menuItem->setTitle($menuItem->getTitle() . " (". $data["c1"] . ")");

}



It work great!!! Thanks!!!