Hi.

This is a piece of code that I wrote for a one of my modules in Joomla 1.5, and im afraid im not skilled enough yet to do this procedure in the correct way..

Please can someone help me structure this code in the right way - the actual code is fine, it just doesnt do its job properly..

Its pretty much the end bit - the if (x = y & a = b) parts...


Any help would be much appreciated

Thanks
Chris

//  Uddeim Notification Extract	
$query = "SELECT firstname FROM #__comprofiler WHERE id = ". (int)$my->id;
$sql="SELECT id FROM #__menu WHERE link LIKE '%com_uddeim%' AND published>=0 LIMIT 1";

$database->setQuery($sql);
$allmessages=$database->loadObjectList();
$totalmessages=count($allmessages);

$pms_link = sefRelToAbs("index.php?option=com_uddeim&task=inbox".($item_id ? "&Itemid=".$item_id : ""));

	if ( $totalpendingconnections === null ) trigger_error( $_CB_database->getErrorMsg(), E_USER_WARNING );
	if($totalpendingconnections > 0) {
		$results .= "<div><a href='".cbSef("index.php?option=com_comprofiler&amp;task=manageConnections".$andItemid)."' class='mod_login".$class_sfx."'>".$totalpendingconnections." "._UE_CONNECTIONREQUIREACTION."</a></div>";
} else {
$results = null;
}

if($totalmessages > 0) {
	$results2 .= "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: You have a <a href='$pms_link'>new message</a>";
} else {
$results2 = null;
}


if($results==null & $results2==null) {
echo "<img src='http://www.capetownalive.co.za/modules/mod_s4jrandomprofile/images/user.png'> Friends: " . _UE_NOACTIONREQUIRED;
echo "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: No new messages";
} elseif ($results==null & $results2 !==null) {
	echo "<img src='http://www.capetownalive.co.za/modules/mod_s4jrandomprofile/images/user.png'> Friends: " . _UE_NOACTIONREQUIRED;
	echo "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: You have a <a href='$pms_link'>new message</a>";
} elseif ($results2==null & $results!==null) {
	echo $results;
	echo "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: No new messages";
}
}

Hi.

This is a piece of code that I wrote for a one of my modules in Joomla 1.5, and im afraid im not skilled enough yet to do this procedure in the correct way..

Please can someone help me structure this code in the right way - the actual code is fine, it just doesnt do its job properly..

Its pretty much the end bit - the if (x = y & a = b) parts...


Any help would be much appreciated

Thanks
Chris

//  Uddeim Notification Extract	
$query = "SELECT firstname FROM #__comprofiler WHERE id = ". (int)$my->id;
$sql="SELECT id FROM #__menu WHERE link LIKE '%com_uddeim%' AND published>=0 LIMIT 1";

$database->setQuery($sql);
$allmessages=$database->loadObjectList();
$totalmessages=count($allmessages);

$pms_link = sefRelToAbs("index.php?option=com_uddeim&task=inbox".($item_id ? "&Itemid=".$item_id : ""));

	if ( $totalpendingconnections === null ) trigger_error( $_CB_database->getErrorMsg(), E_USER_WARNING );
	if($totalpendingconnections > 0) {
		$results .= "<div><a href='".cbSef("index.php?option=com_comprofiler&amp;task=manageConnections".$andItemid)."' class='mod_login".$class_sfx."'>".$totalpendingconnections." "._UE_CONNECTIONREQUIREACTION."</a></div>";
} else {
$results = null;
}

if($totalmessages > 0) {
	$results2 .= "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: You have a <a href='$pms_link'>new message</a>";
} else {
$results2 = null;
}


if($results==null & $results2==null) {
echo "<img src='http://www.capetownalive.co.za/modules/mod_s4jrandomprofile/images/user.png'> Friends: " . _UE_NOACTIONREQUIRED;
echo "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: No new messages";
} elseif ($results==null & $results2 !==null) {
	echo "<img src='http://www.capetownalive.co.za/modules/mod_s4jrandomprofile/images/user.png'> Friends: " . _UE_NOACTIONREQUIRED;
	echo "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: You have a <a href='$pms_link'>new message</a>";
} elseif ($results2==null & $results!==null) {
	echo $results;
	echo "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: No new messages";
}
}

Hi,

Are you creating this from scratch or hacking an existing uddleIM component/plugin etc. The missing part of the code makes it hard to follow..

I can point out what I think may be problem but I'm just guessing...

The first part:

$sql="SELECT id FROM #__menu WHERE link LIKE '%com_uddeim%' AND published>=0 LIMIT 1";

$database->setQuery($sql);
$allmessages=$database->loadObjectList();
$totalmessages=count($allmessages);

$pms_link = sefRelToAbs("index.php?option=com_uddeim&task=inbox".($item_id ? "&Itemid=".$item_id : ""));

You've put a limit 1 into the query, so you'll only receive 0 or 1 row. So it's best to use: $database->loadObject($message); instead of ->loadObjectList($allmessages).

That way you get an Object instead of an array or Objects as the result.

In some of the comparisons you're using &.

eg:

if($results==null & $results2==null) {

You probably want a && instead of single &. The single & is a bitwise operator while && is a boolean operator.

What & does is take the binary value of the two sides, and puts them on top of each other. eg:


1 & 2

would be

01
10

And then it would add up those that have 1 for each top and bottom corresponding columns. In this case it would give you false. While with && it is true, since any integer other then 0 is converted to true by PHP in a boolean operation.

Whats happening in your case is you have:

$results==null & $results2 !==null

which is not equivalent to:

$results==null && $results2 !==null

so you're probably getting the wrong results from what you want.


Also, the use of !== also compares the Type. So you're comparing a string to a boolean, which is always boolean false.
You will want to use != instead of !== as PHP will first convert the type to Boolean before comparing.

So:

$results==null && $results2 !==null

should probably be:

$results==null && $results2 !=null

or just

!$results && !$results2

hope that helps a bit..

Thanks for the help and suggestions, I have redone it to be like this now:

Getting this error though:

Parse error: syntax error, unexpected T_CONCAT_EQUAL in /var/www/modules/mod_comprofilermoderator/mod_comprofilermoderator.php on line 126

if($totalpendingconnections > 0) {

$results .= "<div><a href='".cbSef("index.php?option=com_comprofiler&amp;task=manageConnections".$andItemid)."' class='mod_login".$class_sfx."'>".$totalpendingconnections." "._UE_CONNECTIONREQUIREACTION."</a></div>";

} else {

$results = null;

}

if($totalmessages > 0) {

$results2 .= "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: You have a <a href='$pms_link'>new message</a>";

} else {

$results2 = .= "Messages: No New Messages";

}


if(!$results && !$results2) {
	echo $results;
	echo $results2;
} elseif (!$results && $results2!=null) {
	echo $results;
	echo $results2;
} elseif (!$results2 && $results!=null) {
	echo $results;
	echo $results2;
} elseif ($results2!=null && $results!=null) {
	echo $results;
	echo $results2;
}
}

Thanks for the help and suggestions, I have redone it to be like this now:

Getting this error though:

Parse error: syntax error, unexpected T_CONCAT_EQUAL in /var/www/modules/mod_comprofilermoderator/mod_comprofilermoderator.php on line 126

if($totalpendingconnections > 0) {

$results .= "<div><a href='".cbSef("index.php?option=com_comprofiler&amp;task=manageConnections".$andItemid)."' class='mod_login".$class_sfx."'>".$totalpendingconnections." "._UE_CONNECTIONREQUIREACTION."</a></div>";

} else {

$results = null;

}

if($totalmessages > 0) {

$results2 .= "<br><img src='components/com_uddeim/templates/default/images/menu_inbox.gif'> Messages: You have a <a href='$pms_link'>new message</a>";

} else {

$results2 = .= "Messages: No New Messages";

}


if(!$results && !$results2) {
	echo $results;
	echo $results2;
} elseif (!$results && $results2!=null) {
	echo $results;
	echo $results2;
} elseif (!$results2 && $results!=null) {
	echo $results;
	echo $results2;
} elseif ($results2!=null && $results!=null) {
	echo $results;
	echo $results2;
}
}

It looks like this line:

$results2 = .= "Messages: No New Messages";

the = .= is a syntax error.

thanks you are right, can you see any reason why the script would not be working otherwise? still having problems with it..

thanks you are right, can you see any reason why the script would not be working otherwise? still having problems with it..

How are $results and $results2 related?
What are you trying to do?

The if/else block with $results and $results2 probably insn't necessary, just do:

echo $results.$results2;

If either is empty, they just won't show anything.

This article has been dead for over six months. Start a new discussion instead.