【问题标题】:Joomla JFactory SelectJoomla JFactory 选择
【发布时间】:2015-05-25 16:26:51
【问题描述】:

我有这段代码试图从表中获取数据:

<?php
    define( '_JEXEC', 1 );
    define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../' ));  
    require_once ( $_SERVER['DOCUMENT_ROOT'].'/xampp/hobbies/includes/defines.php' );
    require_once ( $_SERVER['DOCUMENT_ROOT'].'/xampp/hobbies/includes/framework.php' );

    $db =& JFactory::getDbo();
    $query = $db->getQuery(true);
    $query = 'SELECT * FROM vftd8_community_events';

    $db->setQuery($query,0,30);

    $results = $db->loadObjectList();
    if ($db->getErrorNum()) {
         echo $db->getErrorMsg();
         exit;
    }

    return (array) $results;
?>

结果集为空,表有数据。它不返回错误。 请我需要帮助。谢谢大家。

【问题讨论】:

    标签: php joomla


    【解决方案1】:
    <?php
    // No direct access to this file
    defined('_JEXEC') or die;
    
    $db=Jfactory::getDBO();
    
    $select='select * from `#__community_events` ';
    $db->setQuery($select);
    
    $res=$db->loadObjectList(); // for multiple records
    //$product_data=$db->loadObject(); // for single row records
    
    foreach ($res as $result)
    {
       echo $result->id;
       // and whatever you need to print here
    }
    ?>
    

    【讨论】:

    • 该代码与我的旧代码具有相同的结果,可能是问题出在上面吗?我没有像模块一样使用代码,我没有 helper.php,modulename.php 也没有 .xml 文件。我正在使用 .js 主模板文件(测试)中的 ajax,调用我昨天共享的唯一 .php 文件。这可能是我问题的原因吗?非常感谢。
    • It Works!,复制模块内容,非常感谢。
    • 如果您得到答案,请批准。这样其他人也能得到答案。
    • 我建议您使用 Joomla API 中的正确子句,而不是像这样编写原始 SQL 查询。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 2016-10-25
    • 2012-08-11
    • 2014-01-05
    相关资源
    最近更新 更多