2010-01-21 61 views

回答

0
具有適當的JTable時

最好的方式,你就可以說裏面MVC更優雅

$db = &JFactory::getDbo(); 
$sql = 'SELECT * FROM #__table WHERE id ='.$id; 
$db->setQuery($sql); 
$object = $db->loadObject(); 

OFC:

$row =& JTable::getInstance('my_table', ''); 
$row->load($id); 

沒有JTable中工作時。但對於初學者來說可能夠了。

0
$db = JFactory::getDBO(); 

$query = "select id,title from #__content"; 

$db->setQuery($query); 

$result = $db->loadObjectList();//here we got array of stdClass===prepared objects in PHP 5.3 

foreach($result as $res){ 
    echo $res->id."".$res->title; 
} 
相關問題