Retrieve data from database

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.
User avatar
robilro1
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 112
Joined: Thu Nov 22, 2007 1:10 pm
Location: Romania
Contact:

Retrieve data from database

Postby robilro1 » Thu Jul 17, 2008 5:18 pm

Hi!

How do I retrieve data from a table in Joomla 1.5 without using MCV?

Thank you!
Robintel BMS.
"Cine o cauta suficient o gaseste!" ("The one looking for it long enough, will find it!")

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1198
Joined: Sat Feb 11, 2006 8:32 am
Location: Tilburg, Holland
Contact:

Re: Retrieve data from database

Postby carsten888 » Sun Jul 20, 2008 11:43 am

I don't know what you mean with MCV, but this is the code i always use:

Code: Select all

$db = JFactory::getDBO();

$query = "SELECT content_id"
. " FROM #__content_frontpage"
. " WHERE content_id = $item_id"
. " LIMIT 1"
;
$db->setQuery($query);
$rows = $db->loadObjectList();
$itemrow = $rows[0];
$on_frontpage = $itemrow->content_id;
http://www.pages-and-items.com
Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, Access-Manager, Redirect-on-Login, Pages-and-Items, module Admin-Messages, module Logged-in-Users, plugin load module in article, plugin pure css tooltip and more...

User avatar
robilro1
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 112
Joined: Thu Nov 22, 2007 1:10 pm
Location: Romania
Contact:

Re: Retrieve data from database

Postby robilro1 » Mon Jul 21, 2008 11:03 am

Hi!

Thanks.

My second question is: what do these lines mean?

Thanks again.
Robintel BMS.
"Cine o cauta suficient o gaseste!" ("The one looking for it long enough, will find it!")

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1198
Joined: Sat Feb 11, 2006 8:32 am
Location: Tilburg, Holland
Contact:

Re: Retrieve data from database

Postby carsten888 » Mon Jul 21, 2008 3:28 pm

My second question is: what do these lines mean?

er... :geek:

make an instance of the database-object (joomla 1.5.x only)

Code: Select all

$db = JFactory::getDBO();


make a query to select something from the database.

Code: Select all

$query = "SELECT content_id"
. " FROM #__content_frontpage"
. " WHERE content_id = $item_id"
. " LIMIT 1"
;


execute the query

Code: Select all

$db->setQuery($query);


get the results of the query back as a object

Code: Select all

$rows = $db->loadObjectList();


in this bit of code I only needed the data from one row

Code: Select all

$itemrow = $rows[0];


read value from some table's row's column

Code: Select all

$on_frontpage = $itemrow->content_id;


:)

hope that helps
http://www.pages-and-items.com
Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, Access-Manager, Redirect-on-Login, Pages-and-Items, module Admin-Messages, module Logged-in-Users, plugin load module in article, plugin pure css tooltip and more...

User avatar
robilro1
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 112
Joined: Thu Nov 22, 2007 1:10 pm
Location: Romania
Contact:

Re: Retrieve data from database

Postby robilro1 » Tue Jul 22, 2008 9:12 am

:D That helps, thanks! :D

My "not so bright" question is: does the DB instance ($db = JFactory::getDBO();) work with PostgreSQL too, or this is only used to retrieve data from the Joomla MySQL database?

:pop

Thanks!
Robintel BMS.
"Cine o cauta suficient o gaseste!" ("The one looking for it long enough, will find it!")

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1198
Joined: Sat Feb 11, 2006 8:32 am
Location: Tilburg, Holland
Contact:

Re: Retrieve data from database

Postby carsten888 » Tue Jul 22, 2008 1:19 pm

does the DB instance...work with PostgreSQL too

sorry, don't know. maybe you should test that. ;)
http://www.pages-and-items.com
Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, Access-Manager, Redirect-on-Login, Pages-and-Items, module Admin-Messages, module Logged-in-Users, plugin load module in article, plugin pure css tooltip and more...


Return to “Joomla! Coding 101”

Who is online

Users browsing this forum: No registered users and 1 guest