Hide empty menu item

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
droogers
User
Posts: 72

Hide empty menu item

Post by droogers »

How do I hide a menu item when the report is empty ? (v2023)


arbei
User
Posts: 9284

Post by arbei »

You may use MenuItem_Adding server event in which you may use ExecuteScalar() to select "SELECT COUNT(*) FROM..." to check the number of records in your report.


droogers
User
Posts: 72

Post by droogers »

I tried this code but it doesn't work:

$sSql = "SELECT COUNT(*) FROM `html1`)=0"
if ($Item->Url == "deelnemersconferentiedag" && ExecuteScalar($sSql) { // <-- menu items to hide
	$Item->text = "Deelnemers Conferentiedag";
	return FALSE;
	}    return true;

}

arbei
User
Posts: 9284

Post by arbei »

droogers wrote:

$sSql = "SELECT COUNT(*) FROM html1)=0"

Wrong SQL.

droogers wrote:

if ($Item->Url == "deelnemersconferentiedag" && ExecuteScalar($sSql) { // <-- menu items to hide

Wrong syntax.


droogers
User
Posts: 72

Post by droogers »

Oke. I see that the SQL is wrong but what is the good syntax of
if ($Item->Url == "deelnemersconferentiedag" && ExecuteScalar($sSql) { // <-- menu items to hide


mobhar
User
Posts: 11660

Post by mobhar »

Since you are using v2023, there are no $Item object in MenuItem_Adding server event. You should use $item (lower case) instead.


droogers
User
Posts: 72

Post by droogers »

I changed the code but this also didn't work.

function MenuItem_Adding($item)
{
if ($item->Url == "deelnemersconferentiedag" && ExecuteScalar("SELECT COUNT(*) FROM html1=77") { // <-- menu items to hide
$item->text = "Deelnemers Conferentiedag";
return FALSE;
} return true;
}


arbei
User
Posts: 9284

Post by arbei »

You may read and learn Counting Rows.


mobhar
User
Posts: 11660

Post by mobhar »

Double check your code. It has wrong syntax.

If you write the code that includes the brackets, then make sure the count of open bracket is same as the count of clos bracket.


droogers
User
Posts: 72

Post by droogers »

I changed the code and now it is working:

function MenuItem_Adding($item)
{
if ($item->Url == "deelnemersconferentiedag" && (ExecuteScalar("SELECT COUNT(*) FROM html1")==77)) { // <-- menu items to hide
	$item->text = "Deelnemers conferentiedag";
	return FALSE;
	}
return TRUE;
}

Post Reply