这是我使用的代码,我将添加一个div类以供联机和脱机使用,可以从本网站上的示例中尝试一下,但会在脚本中出错

if ($entry['User']['user_id'] > 0)
{
    $db = JFactory::getDbo();
    $query = sprintf('
            SELECT s.userid
            FROM #__session AS s
            WHERE s.guest = 0 AND s.userid = %d
            LIMIT 1', $entry['User']['user_id']);

    $userid = $db->setQuery($query)->loadResult();

    if ($userid) {
        return "Online";
    }
}
return "Offline";


这是离线和离线的div类的css;

.online {
position: absolute;
top: -4px;
right: -6px;
width: 12px;
height: 12px;
border-radius: 50%;
background-color: #39b54a;
border: 2px solid #fff;
   }

.offline {
position: absolute;
top: -4px;
right: -6px;
width: 12px;
height: 12px;
border-radius: 50%;
background-color: #39b54a;
border: 2px solid #fff;
}


我尝试这样做但出现错误:

if ($entry['User']['user_id'] > 0)
{
    $db = JFactory::getDbo();
    $query = sprintf('
            SELECT s.userid
            FROM #__session AS s
            WHERE s.guest = 0 AND s.userid = %d
            LIMIT 1', $entry['User']['user_id']);

    $userid = $db->setQuery($query)->loadResult();

<div class=online>
if ($userid) {
     return "Online";
}</div>
}
<div class=offline>
return "Offline";
</div>

最佳答案

改变这个烂摊子

 <div class=online>
  if ($userid) {
      return "Online";
   }</div>
  }
 <div class=offline>
 return "Offline";</div>


变成这样

  if ($userid) {
      return "<div class=online>Online</div>";
   }
  }

 return "<div class=offline>Offline</div>";

关于php - 如果返回,则在php中添加div类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48816088/

10-10 01:36