0

在此处遵循本教程:http: //docs.joomla.org/Selecting_data_using_JDatabase#Selecting_Records_from_a_Single_Table

我创建了一个函数,如下所示:

function getItemForBid() {
        // Get a db connection.
        $db = JFactory::getDbo();

        // Create a new query object.
        $query = $db->getQuery(true);

        // Select item record matching the $orderID
        $query
            ->select($db->quoteName(array('id', 'created_by', 'itemtitle', 'deliverydestination', 'listprice')))
            ->from($db->quoteName('#__entrusters_items'))
            ->where('id = '.$_GET['orderID']);           
        // Reset the query using our newly populated query object.
        $db->setQuery($query);

        // Load the results as a list of stdClass objects (see later for more options on retrieving data).
$db->setQuery($query);
$bidItem = $db->loadObject();
//print_r($bidItem);
}

print_r($bidItem);作品和回报,例如:

stdClass Object ( 
    [id] => 4 
    [created_by] => 216 
    [itemtitle] => Tennis Racket 
    [deliverydestination] => London 
    [listprice] => 5000 
)

但是,如果我尝试在页面上的其他位置回显其中一个值,例如:

<input name="jform[item_id]" id="jform_item_id" value="<?php echo $bidItem->id; ?> " readonly="" type="text">

我什么都得不到。该手册说您可以使用以下方法访问各个值:

$result->index // e.g. $result->email

我在做一些非常愚蠢的事情吗?

4

2 回答 2

1

首先,不要$_GET与 Joomla 一起使用,你应该像这样使用 JInput:

$jinput = JFactory::getApplication()->input;
$orderID = $jinput->get('orderID', null, null);

至于您的数据库查询,请尝试更改loadObject();loadObjectList();

然后也不要忘记改变这个:

->where('id = '.$_GET['orderID']);  

对此:

->where('id = '. $orderID);  
于 2014-02-28T18:22:17.553 回答
0

$bidItem 对于您创建的函数是本地的。将其声明为全局以在页面的其他位置使用它。修改函数的最后几行,如:

    global $bidItem;
    $bidItem = $db->loadObject();
}

然后在您在 HTML 中使用它之前添加:

<?php global $bidItem; ?>
于 2014-02-28T18:21:16.107 回答