简体   繁体   中英

Joomla JFactory Select

I have this code trying to get data from a table:

<?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;
?>

The result set is empty, and the table has data. It does not return errors. Please I need help. Thanks to you all.

<?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
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM