PDA

View Full Version : Combine 2 parts of mysql, how?


Dark Jim
04-30-2003, 08:07 PM
I have this query in privatemessage.php:
$messages = $DB_site->query("SELECT
privatemessage.*,
IF(ISNULL(touser.username),'[Deleted User]',touser.username) AS tousername,
IF(ISNULL(fromuser.username),'[Deleted User]',fromuser.username) AS fromusername,
icon.title AS icontitle,icon.iconpath
".iif($iconavatarenabled,",iconavatar.iconavatarpath,NOT ISNULL(customiconavatar.iconavatardata) AS hascustomiconavatar,customiconavatar.dateline AS iconavatardateline","")."
FROM privatemessage
LEFT JOIN icon ON icon.iconid=privatemessage.iconid
LEFT JOIN user AS touser ON (touser.userid=privatemessage.touserid)
LEFT JOIN user AS fromuser ON (fromuser.userid=privatemessage.fromuserid)
".iif($iconavatarenabled && privatemessage.userid!=privatemessage.touserid,"LEFT JOIN iconavatar ON iconavatar.iconavatarid=touser.iconavatarid LEFT JOIN customiconavatar ON customiconavatar.userid=touser.userid","")."
WHERE privatemessage.userid='$bbuserinfo[userid]'
AND folderid='".intval($folderid)."'
$ignoreusers
$dateconds
ORDER BY dateline DESC");

This part:
".iif($iconavatarenabled && privatemessage.userid!=privatemessage.touserid,"LEFT JOIN iconavatar ON iconavatar.iconavatarid=touser.iconavatarid LEFT JOIN customiconavatar ON customiconavatar.userid=touser.userid","")."
needs to somehow combined with:
".iif($iconavatarenabled && privatemessage.userid!=privatemessage.fromuserid,"LEFT JOIN iconavatar ON iconavatar.iconavatarid=fromuser.iconavatarid LEFT JOIN customiconavatar ON customiconavatar.userid=fromuser.userid","")."

How would I do that? I tried a few things and nothing worked. Seaching for "iif" on php.net and mysql.com didn't work. :(

filburt1
04-30-2003, 09:02 PM
iif is in functions.php and is identical to the construct:

$something = iif($condition, $truevalue, $falsevalue);
// same as:
$something = ($condition ? $truevalue : $falsevalue);

Theoretically, though, the second one is slightly faster.