This topic is locked

Record Count in Menu For Tables and Views

4/2/2011 7:25:36 PM
PHPRunner General questions
S
salus1 authorDevClub member

Hi,

I added the following code from the example to the "Menu item: Modify" event to append the count of records in tables and views to their corresponding menu entry...
if($menuItem->getLinkType() == 'Internal')

{

global $tables_data;

$table=$menuItem->getTable();

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

$table=GetOriginalTableName($table);

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

$data = db_fetch_array($rs);

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

}

return true;
...which works great for table menus but not for views menus (it displays the record count for all records in the underlying table, not the filtered results).

Any suggestions?

Thanks!

Sergey Kornilov admin 4/5/2011

You will have to write a separate query for each custom view manually.
See examples at http://www.asprunner.com/forums/topic/16735-menu-item-advanced/

S
salus1 authorDevClub member 4/8/2011

Sergei,

Thanks for this code. I imagine this works for views defined in MySQL but it doesn't work for Custom Views defined in PHPRunner. It throws a "can't find table..." error instead. Any way I can make this work for PHPRunner-generated Custom Views?

Thanks!

Sergey Kornilov admin 4/8/2011

This example is specifically for Custom Views defined in PHPRunner. Make sure you specify SQL query for each custom view in your code.