开发者

How to connect the Db and get the data from table in Joomla php

I want to connect the Joomla DB and i have created table in PHPmyAdmin. And want to get the row and val开发者_如何学Pythonues from the field.


Best way when having a proper JTable:

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

When working without JTable:

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

OFC you can make that more elegant inside MVC. BUT for starters maybe enough.


$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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜