如果用户的行包含值,则回显html

时间:2012-12-08 02:18:03

标签: php if-statement joomla echo

我正在使用Joomla网站,当用户在某个程序中完成某个测验时,我想在其个人资料中显示验证图形和文本。我有大部分代码完成,但我不能让它做我想要的。这就是我所拥有的:


        $db = &JFactory::getDBO();

        $uri    = JURI::base();
        $my     =& JFactory::getUser();
        $user   =& CFactory::getActiveProfile();

        $query = 'select distinct(a.id), a.title, a.alias, a.description, a.created, a.responses, c.title as category'
            . ' from #__quiz_quizzes a left join #__quiz_categories c on a.catid=c.id left join #__quiz_responses r on a.id=r.quiz_id'
            . ' where r.created_by='.$user->id.' and a.published=1 order by a.created desc';
        $db->setQuery($query, 0, 10);
        $items = $db->loadObjectList();
            $menu = &JSite::getMenu();
            $mnuitems   = $menu->getItems('link', 'index.php?option=com_communityquiz&view=quiz');
            $itemid = isset($mnuitems[0]) ? '&Itemid='.$mnuitems[0]->id : '';
    if (strpos($itemid,'3')) {
    echo " Rep is Verified";
    } else {
    echo " Rep is not Verified {SHOW_FOR profile_owner} How to get verified{/SHOW_FOR}{HIDE_FOR profile_owner}  What does this mean?{/HIDE_FOR}";
    echo "";
    }

麻烦的是,如果有人使用id为'3'进行测试,则说它们已经过验证。如果quiz_id等于'3',并且created_by字段与$user匹配,我需要它才显示已验证的部分。我的代码取自原始插件,所有这些都可能不需要这么小的功能,帮助精简将不胜感激! Screenshot of database table

1 个答案:

答案 0 :(得分:0)

我认为我在Stack Overflow上使用其他论坛条目的组合发现了它。这有效:

    $user   =& CFactory::getActiveProfile();
    $result = mysql_query("SELECT COUNT(*) AS num_rows FROM hxlth_quiz_responses WHERE created_by='{$user->id}' and quiz_id='3' and score='3' LIMIT 1;");
    $row = mysql_fetch_array($result);
    if($row["num_rows"] > 0){
    echo "<div style='margin: 0 15px 15px 0; padding: 5px; box-shadow: rgba(0,0,0,0.4) 1px 1px; border: 1px solid #cccccc;'><img src='/images/check1.jpg' align='absmiddle' width='22' height='21' /> Rep is Verified</div>";
    } else {
    echo "<div style='margin: 0 15px 15px 0; padding: 5px; box-shadow: rgba(0,0,0,0.4) 1px 1px; border: 1px solid #cccccc;'><img src='/images/x1.jpg' align='absmiddle' width='21' height='21'> Rep is not Verified {SHOW_FOR profile_owner}<a href='index.php?option=com_communityquiz&view=quiz&task=respond&id=3'><font size='1'> How to get verified</font></a>{/SHOW_FOR}{HIDE_FOR profile_owner} <a href='index.php?option=com_communityquiz&view=quiz&task=respond&id=3'><font size='1'> What does this mean?</font>{/HIDE_FOR}";
    echo "</a></div>";
    }

它现在正确显示图形和文字,我甚至在一个AND分数变量中滑动以确保它们实际通过了测验!