How do I add an factory to any of my logged in users? I'm using Tank_auth and I made an account 'admin' I also made a table called 'factoryusers'.
I want to add a factory to a specific user using joins.
My table structure:
users
-----
id
username
email
...
...
factories
---------
idfactories
factoryname
adress
...
...
factoryusers
------------
idfactoryusers
idusers
idfactories
I tried to join these tables and show the records from the factoryusers table.
My controller function:
$data['userbedrijf'] = $this->bedrijven_model->bedrijvenusers();
(translation to english: $data['userfactory'] = $this->factory_model->factoryusers();)
My model:
function bedrijvenusers()
{
$this->db->join('bedrijven', 'bedrijfusers.idbedrijven = bedrijven.idbedrijven');
$this->db->join('users', 'bedrijfusers.idusers = users.id');
$result = $this->db->get('bedrijfusers', 1);
return $result->result();
}
My views:
<h4>Gebruikergegevens:</h4>
<p class="field"><label class="field">Gebruikersnaam:</label> <?= $this->tank_auth->get_username(); ?></p>
<p class="field"><label class="field">Emailadres:</label> <?= $user_data->email; ?></p>
<p class="field"><label class="field">Laatste Login:</label> <?= date ("d-M-Y H:i:s",strtotime($user_data->last_login)); ?></p>
<p class="field"><label class="field">Account aangemaakt:</label> <?= date ("d-M-Y H:m:s",strtotime($user_data->created)); ?></p>
<p class="field"><label class="field">Laatst aangepast:</label> <?= date ("d-M-Y H:i:s",strtotime($user_data->modified)); ?></p>
<p class="field"><label class="field">is admin:</label> <?= $user_data->is_admin; ?></p>
<hr>
<h4>Bedrijfsgegevens:</h4>
<? foreach($userbedrijf as $row){ ?>
<p class="field"><label class="field">Bedrijf_id:</label> <?= $row->idbedrijven; ?></p>
<p class="field"><label class="field">Bedrijfsnaam:</label> <?= $row->Bedrijfsnaam; ?></p>
<p class="field"><label class="field">Adres:</label> <?= $row->Adres; ?></p>
<p class="field"><label class="field">Postcode:</label> <?= $row->Postcode; ?></p>
<p class="field"><label class="field">Plaats:</label> <?= $row->Plaats; ?></p>
<p class="field"><label class="field">Telefoonnummer:</label> <?= $row->Telefoonnummer; ?></p>
<p class="field"><label class="field">Website:</label> <?= $row->Website; ?></p>
<p class="field"><label class="field">Email:</label> <?= $row->Email; ?></p>
<p class="field"><label class="field">Profiel:</label> <?= $row->Profiel; ?></p>
<?}?>
What's wrong with my joins? it shows me factories. but for each user the factory is the same. even when i have multiple factoryuser rows in my database with different user id's and factory id's