Hey,
I'm relatively new to developing for Joomla! so this may seem a stupid question but how does Joomla! manage dealing with multiple tables within a single component. I know about using an extension of the JTable class which utilises a __construct function.
However I have only worked with this file refering to one table and what I need to do now is link several tables together. Can anyone tell me how to do this or show me a good example or even a tutorial.
Many thanks.
Database management query.
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
Forum rules
Database management query.
Last edited by reashlin on Sun Dec 16, 2007 5:12 pm, edited 1 time in total.
- manuman
- Joomla! Enthusiast
- Posts: 211
- Joined: Fri Aug 12, 2005 1:58 am
- Location: Albany - Western Australia
- Contact:
Re: Database management query.
It would depend on what your doing, is it a simple relationship you can do in a standard select or one to many?
If you can provide a bit more detail I can probably assist.
Cheers
Shayne
If you can provide a bit more detail I can probably assist.
Cheers
Shayne
Core Team Member :: Project Manager & Foundation WG Coordinator
OSM Board Member :: Treasurer
Vote for Joomla! http://www.packtpub.com/nominations-homepage
OSM Board Member :: Treasurer
Vote for Joomla! http://www.packtpub.com/nominations-homepage
Re: Database management query.
The relationship is fairly simple. I have 5 tables
The plan is to have it so I can add features regions and descriptions as the list of hotels I have grows.
As I say I like the use of the tables file that many Joomla! components use and would like to use such a file myself. However I cannot work out how to put multiple tables within this file.
- hotels - Contains a list of hotels and their main details
- hotel_featurelist - links hotels to features
- hotel_features - lists features hotels may have
- hotel_descriptions - describes the type of hotel
- hotel_nearest_regions - describes the hotels nearest region
The plan is to have it so I can add features regions and descriptions as the list of hotels I have grows.
As I say I like the use of the tables file that many Joomla! components use and would like to use such a file myself. However I cannot work out how to put multiple tables within this file.
Last edited by reashlin on Fri Dec 14, 2007 5:09 pm, edited 1 time in total.
Re: Database management query.
This post is getting many views but not many replies so I am guessing that I am not being detailed enough and so will try to elaborate a little here.
I have a component under development called "hotels".
So my com_hotels folder as of now looks like
..
tables
->hotels.php
admin.hotels.html.php
admin.hotels.php
toolbar.hotels.html.php
toolbar.hotels.php
My current "tables/hotels.php" looks like
If I were to add a row from the tables in my database it would look like
This means that later in my component I can refer directly to the "var $id" to manipulate it.
However what I want to do is build a relational database for my component and so I require access to more than one table. I can use SELECT queries to access the data in other tables without a problem. However I would like to INSERT and UPDATE values in other tables and this is where I am having a problem.
I am using functions of Joomla that work out what should be happening in these circumstances (ie. UPDATE or INSERT) by referring just to the "var $x" value.
can this "tables/hotels.php" file be adjusted to refer to many different tables or not. If so how do I do this.
I have a component under development called "hotels".
So my com_hotels folder as of now looks like
..
tables
->hotels.php
admin.hotels.html.php
admin.hotels.php
toolbar.hotels.html.php
toolbar.hotels.php
My current "tables/hotels.php" looks like
Code: Select all
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
class TableHotels extends JTable {
function __construct(&$db) {
parent::__construct( '#__hotels', 'id', $db );
}
}
?>
If I were to add a row from the tables in my database it would look like
Code: Select all
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
class TableHotels extends JTable {
// The additional line of code.
var $id = null;
function __construct(&$db) {
parent::__construct( '#__hotels', 'id', $db );
}
}
?>
This means that later in my component I can refer directly to the "var $id" to manipulate it.
However what I want to do is build a relational database for my component and so I require access to more than one table. I can use SELECT queries to access the data in other tables without a problem. However I would like to INSERT and UPDATE values in other tables and this is where I am having a problem.
I am using functions of Joomla that work out what should be happening in these circumstances (ie. UPDATE or INSERT) by referring just to the "var $x" value.
can this "tables/hotels.php" file be adjusted to refer to many different tables or not. If so how do I do this.
Re: Database management query.
OK,
The problem is that I didnt have multiple files within the tables drectory, one relating to each table within the database.
The problem is that I didnt have multiple files within the tables drectory, one relating to each table within the database.