Advertisement
External database connect and display table info in article
Moderator: General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
-
- Joomla! Apprentice
- Posts: 5
- Joined: Wed Dec 17, 2014 6:29 pm
External database connect and display table info in article
I've got an external database where I need to connect, and then display data within a Joomla article.
I'm not a big php guy and expesially in Joomla
I have the following to connect:
<?php
$option = array(); //prevent problems
$option['driver'] = 'mysql'; // Database driver name
$option['host'] = 'localhost'; // Database host name
$option['user'] = 'myusername'; // User for database authentication
$option['password'] = 'mypass'; // Password for database authentication
$option['database'] = 'zcars'; // Database name
$db = JDatabaseDriver::getInstance( $option );
?>
I have the following query where I want to get the data from the db and then display within the page
select * from cars where Make_ID = 13 order by model;
Any ideas on best way to get this query to connect to an external db, and then display the data within an article or even a separate php page?
I'm not a big php guy and expesially in Joomla
I have the following to connect:
<?php
$option = array(); //prevent problems
$option['driver'] = 'mysql'; // Database driver name
$option['host'] = 'localhost'; // Database host name
$option['user'] = 'myusername'; // User for database authentication
$option['password'] = 'mypass'; // Password for database authentication
$option['database'] = 'zcars'; // Database name
$db = JDatabaseDriver::getInstance( $option );
?>
I have the following query where I want to get the data from the db and then display within the page
select * from cars where Make_ID = 13 order by model;
Any ideas on best way to get this query to connect to an external db, and then display the data within an article or even a separate php page?
Advertisement
- sohopros
- Joomla! Enthusiast
- Posts: 107
- Joined: Fri Jul 22, 2011 1:51 pm
- Contact:
Re: External database connect and display table info in arti
Hi zc00lness!
There is several ways to approach your issue. Here are a couple suggestions:
1 -Create a Joomla module that executes your query and embed it inside an article using load position.
2 - Create an external php file and load it inside the article with an iframe.
Hope it send you in the correct path!
There is several ways to approach your issue. Here are a couple suggestions:
1 -Create a Joomla module that executes your query and embed it inside an article using load position.
2 - Create an external php file and load it inside the article with an iframe.
Hope it send you in the correct path!
SOHO Prospecting
https://www.sohoprospecting.com - Joomla Website development
Southern California - USA
Phone 866.644.7646
https://www.sohoprospecting.com - Joomla Website development
Southern California - USA
Phone 866.644.7646
-
- Joomla! Exemplar
- Posts: 8808
- Joined: Sat Oct 01, 2011 7:06 pm
Re: External database connect and display table info in arti
Add the following:
Next you will need to add the html code in a foreach $rows as $row and mix it with echo $row-><column name> to put the content of the column there.
Suggest to create a module for it. See docs.jooma.org or take any module as example. No need for the complete structure. Everything could be in <name of module>.php to keep it simple.
Code: Select all
$query = $db->getQuery(true)
->select('*')
->from($db->qn('cars'))
->where($db-qn('Make_ID') . ' = 13')
->order($db->qn('model') . ' ASC');
$db->setQuery($query);
$rows = $db->loadObjectList();
Suggest to create a module for it. See docs.jooma.org or take any module as example. No need for the complete structure. Everything could be in <name of module>.php to keep it simple.
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!
-
- Joomla! Apprentice
- Posts: 5
- Joined: Wed Dec 17, 2014 6:29 pm
Re: External database connect and display table info in arti
Thank you. I have the connection working and will now just see if i can get the html built. I support this all can go into the one php file .. like the helper.php?
-
- Joomla! Apprentice
- Posts: 5
- Joined: Wed Dec 17, 2014 6:29 pm
Re: External database connect and display table info in arti
Also, is there a way to do this without creating a module? if I just have a standalone php file, it should still be able to use the joomla connection right? can i use $db = JDatabaseDriver::getInstance( $option ); from a php file that is not in a module?
-
- Joomla! Exemplar
- Posts: 8808
- Joined: Sat Oct 01, 2011 7:06 pm
Re: External database connect and display table info in arti
Have you seen how many php scripts there are outside of the module folders?
They all run in the context of Joomla which allows them to use the Joomla API.
A module script only determines the context for when the script is run. For different needs, you write different scripts (module/component/plugin/template/library/layout). Sounds like you don't understand the structure!
They all run in the context of Joomla which allows them to use the Joomla API.
A module script only determines the context for when the script is run. For different needs, you write different scripts (module/component/plugin/template/library/layout). Sounds like you don't understand the structure!
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!
-
- Joomla! Apprentice
- Posts: 5
- Joined: Wed Dec 17, 2014 6:29 pm
Re: External database connect and display table info in arti
For sure, I;m a Joomla newbie 
I'll give it a shot and build a module. Was just curious. I had a feeling I;d need to be inside the Joomla container to use the api. I may still try to make this a one file module however. Thank you for your help - I should be able to get this working.

I'll give it a shot and build a module. Was just curious. I had a feeling I;d need to be inside the Joomla container to use the api. I may still try to make this a one file module however. Thank you for your help - I should be able to get this working.
-
- Joomla! Exemplar
- Posts: 8808
- Joined: Sat Oct 01, 2011 7:06 pm
Re: External database connect and display table info in arti
Have a look at cli/deletefiles.php or any of the other scripts in cli. Just as the index.php in the root of the joomla installation it starts with setting up the environment so you can use the joomla API.
So, yes you would need to be inside the Joomla container to use the API. The problem is that these are your words to describe something that is not industry standard, meaning there is no such thing as 'Joomla container'! That makes it very difficult to answer such questions.
So, yes you would need to be inside the Joomla container to use the API. The problem is that these are your words to describe something that is not industry standard, meaning there is no such thing as 'Joomla container'! That makes it very difficult to answer such questions.
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!
-
- Joomla! Apprentice
- Posts: 5
- Joined: Wed Dec 17, 2014 6:29 pm
Re: External database connect and display table info in arti
yeah sorry about that. I live on the JMS world where we use the term "container" quite a bit. I'm not much of a php or Joomla person but helping someone out. If they'd asked me to put this in weblogic and hook up a small small workflow, i'd be done by now. All about what we know I suppose.
Advertisement