$where='touserid='.($toisuserid?'$':'(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)').' AND type=$';
$where='touserid='.($toisuserid?'$':'(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)').' AND type=$';
$source='^messages LEFT JOIN ^users ufrom ON fromuserid=ufrom.userid LEFT JOIN ^users uto ON touserid=uto.userid WHERE '.$where.' ORDER BY ^messages.created DESC LIMIT #,#';
$source='^messages LEFT JOIN ^users ufrom ON fromuserid=ufrom.userid LEFT JOIN ^users uto ON touserid=uto.userid WHERE '.$where.' ORDER BY ^messages.created DESC';
$where='fromuserid='.($fromisuserid?'$':'(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)').' AND type=$';
$where='fromuserid='.($fromisuserid?'$':'(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)').' AND type=$';
$source='^messages LEFT JOIN ^users ufrom ON fromuserid=ufrom.userid LEFT JOIN ^users uto ON touserid=uto.userid WHERE '.$where.' ORDER BY ^messages.created DESC LIMIT #,#';
$source='^messages LEFT JOIN ^users ufrom ON fromuserid=ufrom.userid LEFT JOIN ^users uto ON touserid=uto.userid WHERE '.$where.' ORDER BY ^messages.created DESC';