Page 1 of 1

Retrieve data from database

Posted: Thu Jul 17, 2008 5:18 pm
by robilro1
Hi!

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

Thank you!

Re: Retrieve data from database

Posted: Sun Jul 20, 2008 11:43 am
by carsten888
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;

Re: Retrieve data from database

Posted: Mon Jul 21, 2008 11:03 am
by robilro1
Hi!

Thanks.

My second question is: what do these lines mean?

Thanks again.

Re: Retrieve data from database

Posted: Mon Jul 21, 2008 3:28 pm
by carsten888
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

Re: Retrieve data from database

Posted: Tue Jul 22, 2008 9:12 am
by robilro1
: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!

Re: Retrieve data from database

Posted: Tue Jul 22, 2008 1:19 pm
by carsten888
does the DB instance...work with PostgreSQL too
sorry, don't know. maybe you should test that. ;)