Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7398885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:55:42+00:00 2026-05-29T03:55:42+00:00

Ok so I have a table1 witch contains my main profile data. Then I

  • 0

Ok so I have a table1 witch contains my main profile data.

Then I have table2 witch contains names(and type) of my custom user created fields (My admins can create custom fields for the main profile if they need)

And I have table3 that contains the values for the custom fields in table2. So table 3 refers to table2 for the field name and is linked to the table1 entry.

CREATE TABLE IF NOT EXISTS `table1` (
  `id` int(11) NOT NULL auto_increment,
  `numero_membre` varchar(255) NOT NULL default '',
  `membre` tinyint(1) NOT NULL default '0',
    (...ALOT OF FIELDS, I DONT FEEL THE NEED TO SHOW THEM ALL)
  `ordering` int(10) NOT NULL default '0',
  `dateModified` datetime NOT NULL default '0000-00-00 00:00:00',
  `dateCreated` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
);

CREATE TABLE IF NOT EXISTS `table2` (
  `id` int(10) NOT NULL auto_increment,
  `nom` varchar(255) NOT NULL default '',
  `type` varchar(255) NOT NULL default '',
  `published` tinyint(1) NOT NULL,
  `ordering` int(10) NOT NULL,
  `datemodified` datetime NOT NULL default '0000-00-00 00:00:00',
  `datecreated` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
);

CREATE TABLE `table3` (
    `id` INT(10) NOT NULL AUTO_INCREMENT,
    `idchamps` VARCHAR(255) NOT NULL DEFAULT '',
    `idprofil` VARCHAR(255) NOT NULL DEFAULT '',
    `value` VARCHAR(255) NOT NULL DEFAULT '',
    PRIMARY KEY( `id` )
);

So i want to SELECT all rows in table1 and i want it to join the name from table2 and make its value = from table3 that corresponds.

I was thinking LEFT JOIN. but that would seem to just add like all my table2 field names to the table1… This is complex… i hope you all understand.

If its not possible in 1 query… I think i have an alternative to get the data but this would make my life sooo much easier…


Objective: the User has an export data form. This form he can choose the fields from table1 and table2 that he wants for each entry (with checkboxes). then they can provide filters for ANY given field. such as id=1 or name LIKE %Somthing% to filters the results.

The checkbox values are saved in addfield[]
$this->getFields() returns ALL the fields so it can loop threw the filter post values.

HERE IS MY CODE THAT generates the SQL (part of a class):

function getExportObject() {
    // --> FOR EXPORT
    //Building Query
    $postdata   =   JRequest::get( 'post' );
    $exportFields           = $postdata['addfield'];        //Table 1
    $exportCustomFields = $postdata['addcfield'];       //table 2 name, table 3 value
    $sqlSelect = '';
    //Main profil Fields...
    foreach($exportFields as $key => $field) {
        if ($sqlSelect!='') $sqlSelect .= ', ';
        $sqlSelect .= '`'.$field.'`';
    }

    //Add filters to the SELECT
    //GET LIST OF ALL FIELDS....
    $sqlFilter  = '';
    $loopFields = $this->getFields();
    foreach($loopFields as $key => $field) {
        if (JRequest::getVar('filter_'.$field)!='') {
            if ($sqlFilter=='') { $sqlFilter .= " WHERE "; }
            else { $sqlFilter .= " AND "; }

            switch(JRequest::getVar('filter_'.$field)) {
                case 'EQUAL'                : $sqlFilter .= "`".$field."`='".JRequest::getVar('filter_val_'.$field)."'"; break;
                case 'NOT_EQUAL'        : $sqlFilter .= "`".$field."`!='".JRequest::getVar('filter_val_'.$field)."'"; break;
                case 'CONTAINS'         : $sqlFilter .= "`".$field."` LIKE '%".JRequest::getVar('filter_val_'.$field)."%'"; break;
                case 'NOT_CONTAINS' : $sqlFilter .= "`".$field."` NOT LIKE '%".JRequest::getVar('filter_val_'.$field)."%'"; break;
                default                         : die('Utilisation invalid. SVP. essayez de nouveau.'); break;
            }
        }
    }
    //PUTTING IT ALL TOGETTHER
    //"SELECT t1.*, t2.nom, t3.value FROM table1 t1 LEFT JOIN table3 t3 INNER JOIN table2 t2 ON t3.fieldname = t2.nom ON t1.id = t3.idprofil"
    $query = "SELECT ".$sqlSelect." FROM `table1`".$sqlFilter;
    echo $query;
    exit();
    $this->_db->setQuery($query);
    $exportList = $this->_db->loadObjectList();
    return $exportList;
} //End of getExportObject()

So that function works for getting the values for the table1. i havnt set any of the code for the table2. but lets say table 2 varibles are held in the same way as table 1 but in the post varibale addcfield[]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:55:43+00:00Added an answer on May 29, 2026 at 3:55 am

    Not 100% sure I understand the relationship between table2 and table3, but I think you’re looking for something like this:

    EDIT: Modified query based on feedback in comments. Assuming the table2 id is added to table3.

    SELECT t1.*, t2.nom, t3.value
        FROM table1 t1
            LEFT JOIN table3 t3
                INNER JOIN table2 t2
                    ON t3.table_2_id = t2.id
                ON t1.id = t3.idprofil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with exactly the same fields. Table A contains 7160 records
I have a TABLE elements with one COLUMN number, type SMALLINT that contains numbers
I have a table that contains members names and a field with multiple ID
I have a table which contains sales order data (order number, product number, sales
I have a Mysql table which contains a column of JSON data and a
I have a table with a few thousand rows. The table contains two columns,
I have a table with all U.S. zip codes. each row contains the city
I have the following requirement. I have a table with a column that contains
I have a table that contains records with a column indicates the Date. Given
I have a huge access mdb file which contains a single table with 20-30

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.