Reputation: 89
I made a model function so it will echo the products that belong to the profile user I clicked on, the thing is only the first product of that user gets echoed. For example I have an account that uploaded a total of 7 products and the function only shows the first product on the page..
This are the model functions:
function getdata_aangeboden($user_id){
$this->db->select("users.*,products.*");
$this->db->from('users');
$this->db->join('products','products.user_id = users.user_id','left');
$this->db->where('users.user_id', $user_id);
$query = $this->db->get();
return $query->result();
}
// Gets a list of multiple users.
function getdata($user_id){
$this->db->select("*");
$this->db->from('users');
$this->db->where('user_id', $user_id);
$query = $this->db->get();
return $query->result();
}
Controller function:
<?php foreach($products as $product) { ?>
<div class="main-gifts">
<a href="<?php echo base_url() ?>/Product/details/<?php echo $product->product_id; ?>">
<img id="fotos" src="<?php echo base_url(); ?>upload/<?php echo $product->product_foto_thumb; ?>">
</a>
<div class="products_discription">
<h3><?php echo $product->product_naam; ?></h3>
<div class="ophaal_plaats">
<p>Plaats: <?php echo $product->ophaal_plaats; ?></p>
</div>
<div class="aangeboden_door">
<p> <?php
foreach($userdetail_list as $row){ ?>
<tr>
<td><?php echo $row->voornaam;?></td>
</tr>
<?php } ?></p>
</div>
<div class="status">
</div>
</div>
<a href="<?php echo base_url() ?>/KdGwController/details_bewerken/<?php echo $product->product_id; ?>"><input type="button" class="btn btn-default cb" value="Cadeau bewerken"></input> </a>
</div>
<?php } ?>
Can someone explain to me why it only shows 1 product and not all the products that belong to the same user_id? thanks
When I print $products:
} ?> Array ( [0] => stdClass Object ( [user_id] => 4 [email] => [email protected] [voornaam] => Jeremy [achternaam] => Mathieu [straat] => [huisnummer] => 22 [postcode] => 1223lL [woonplaats] => Rotterdam [wachtwoord] => $2y$10$rO.e4j0dofAUZSWV8sP6yOHYqLzhPkRk9FjBylwbaMMmWRoCBp2oy [beschrijving] => Hallo ik ben Jeremy [geboortedatum] => 2017-06-10 [startdatum] => 2017-06-29 [geslacht] => Man [reset_password_key] => [profiel_foto] => 1498736939jeremy.jpg [product_id] => 85 [product_naam] => HIHIHIHI [product_beschrijving] => [ophaal_plaats] => ALLOVER [product_foto] => new_f5cea9c914751e0ad0048800ffec3d05.jpg [product_foto_thumb] => thumb_f5cea9c914751e0ad0048800ffec3d05.jpg [date_created] => 2017-10-25 [date_updated] => 2017-10-25 [category_id] => 2 ) [1] => stdClass Object ( [user_id] => 4 [email] => [email protected] [voornaam] => Jeremy [achternaam] => Mathieu [straat] => [huisnummer] => 22 [postcode] => 1223lL [woonplaats] => Rotterdam [wachtwoord] => $2y$10$rO.e4j0dofAUZSWV8sP6yOHYqLzhPkRk9FjBylwbaMMmWRoCBp2oy [beschrijving] => Hallo ik ben Jeremy [geboortedatum] => 2017-06-10 [startdatum] => 2017-06-29 [geslacht] => Man [reset_password_key] => [profiel_foto] => 1498736939jeremy.jpg [product_id] => 86 [product_naam] => HUHUUHU [product_beschrijving] => [ophaal_plaats] => NOWHERE [product_foto] => new_ba2430d2b531bc421f27b5f14667cffb.jpg [product_foto_thumb] => thumb_ba2430d2b531bc421f27b5f14667cffb.jpg [date_created] => 2017-10-25 [date_updated] => 2017-10-25 [category_id] => 4 ) [2] => stdClass Object ( [user_id] => 4 [email] => [email protected] [voornaam] => Jeremy [achternaam] => Mathieu [straat] => [huisnummer] => 22 [postcode] => 1223lL [woonplaats] => Rotterdam [wachtwoord] => $2y$10$rO.e4j0dofAUZSWV8sP6yOHYqLzhPkRk9FjBylwbaMMmWRoCBp2oy [beschrijving] => Hallo ik ben Jeremy [geboortedatum] => 2017-06-10 [startdatum] => 2017-06-29 [geslacht] => Man [reset_password_key] => [profiel_foto] => 1498736939jeremy.jpg [product_id] => 87 [product_naam] => HOHOHO [product_beschrijving] => [ophaal_plaats] => NOIDEA [product_foto] => new_e1dfb9a860859ff882d13435e796578c.jpg [product_foto_thumb] => thumb_e1dfb9a860859ff882d13435e796578c.jpg [date_created] => 2017-10-25 [date_updated] => 2017-10-25 [category_id] => 7 ) [3] => stdClass Object ( [user_id] => 4 [email] => [email protected] [voornaam] => Jeremy [achternaam] => Mathieu [straat] => [huisnummer] => 22 [postcode] => 1223lL [woonplaats] => Rotterdam [wachtwoord] => $2y$10$rO.e4j0dofAUZSWV8sP6yOHYqLzhPkRk9FjBylwbaMMmWRoCBp2oy [beschrijving] => Hallo ik ben Jeremy [geboortedatum] => 2017-06-10 [startdatum] => 2017-06-29 [geslacht] => Man [reset_password_key] => [profiel_foto] => 1498736939jeremy.jpg [product_id] => 88 [product_naam] => HEHEHE [product_beschrijving] => [ophaal_plaats] => Korea [product_foto] => new_c080495685ed05ab5d4f8a7dcdb8e668.jpg [product_foto_thumb] => thumb_c080495685ed05ab5d4f8a7dcdb8e668.jpg [date_created] => 2017-10-25 [date_updated] => 2017-10-25 [category_id] => 8 ) [4] => stdClass Object ( [user_id] => 4 [email] => [email protected] [voornaam] => Jeremy [achternaam] => Mathieu [straat] => [huisnummer] => 22 [postcode] => 1223lL [woonplaats] => Rotterdam [wachtwoord] => $2y$10$rO.e4j0dofAUZSWV8sP6yOHYqLzhPkRk9FjBylwbaMMmWRoCBp2oy [beschrijving] => Hallo ik ben Jeremy [geboortedatum] => 2017-06-10 [startdatum] => 2017-06-29 [geslacht] => Man [reset_password_key] => [profiel_foto] => 1498736939jeremy.jpg [product_id] => 89 [product_naam] => ugilh [product_beschrijving] => hjgluhsfkh;sidh fihsdiuhfluisdhauighsudiahguivhadsuihudisahluihvsaduihvluidsahuihv [ophaal_plaats] => Amsterdam [product_foto] => new_c6dd9fa0dc0be0830ed43940b5907115.jpg [product_foto_thumb] => thumb_c6dd9fa0dc0be0830ed43940b5907115.jpg [date_created] => 2017-10-26 [date_updated] => 2017-10-26 [category_id] => 1 ) [5] => stdClass Object ( [user_id] => 4 [email] => [email protected] [voornaam] => Jeremy [achternaam] => Mathieu [straat] => [huisnummer] => 22 [postcode] => 1223lL [woonplaats] => Rotterdam [wachtwoord] => $2y$10$rO.e4j0dofAUZSWV8sP6yOHYqLzhPkRk9FjBylwbaMMmWRoCBp2oy [beschrijving] => Hallo ik ben Jeremy [geboortedatum] => 2017-06-10 [startdatum] => 2017-06-29 [geslacht] => Man [reset_password_key] => [profiel_foto] => 1498736939jeremy.jpg [product_id] => 93 [product_naam] => 11111 [product_beschrijving] => frfewefwe [ophaal_plaats] => 1111 [product_foto] => new_14de53777d648dcbe31dea26fa031ced.jpg [product_foto_thumb] => thumb_14de53777d648dcbe31dea26fa031ced.jpg [date_created] => 2017-10-26 [date_updated] => 2017-10-26 [category_id] => 2 ) [6] => stdClass Object ( [user_id] => 4 [email] => [email protected] [voornaam] => Jeremy [achternaam] => Mathieu [straat] => [huisnummer] => 22 [postcode] => 1223lL [woonplaats] => Rotterdam [wachtwoord] => $2y$10$rO.e4j0dofAUZSWV8sP6yOHYqLzhPkRk9FjBylwbaMMmWRoCBp2oy [beschrijving] => Hallo ik ben Jeremy [geboortedatum] => 2017-06-10 [startdatum] => 2017-06-29 [geslacht] => Man [reset_password_key] => [profiel_foto] => 1498736939jeremy.jpg [product_id] => 94 [product_naam] => hiu;ij [product_beschrijving] => hk;h uihucuhsducuisdhuvsdphvjuisjhuvsudih [ophaal_plaats] => Amsterdam [product_foto] => new_f68becfc0741d3a2300f49ed5bcf58a5.jpg [product_foto_thumb] => thumb_f68becfc0741d3a2300f49ed5bcf58a5.jpg [date_created] => 2017-10-26 [date_updated] => 2017-10-26 [category_id] => 5 ) )
Upvotes: 0
Views: 81
Reputation: 798
i have found that you have only put the
tr
tag, but not the
table
tag, this may cause a issue,so please review my answer below
<?php
foreach($products as $product) { ?>
<div class="main-gifts">
<a href="<?php echo base_url() ?>/Product/details/<?php echo $product->product_id; ?>">
<img id="fotos" src="<?php echo base_url(); ?>upload/<?php echo $product->product_foto_thumb; ?>">
</a>
<div class="products_discription">
<h3><?php echo $product->product_naam; ?></h3>
<div class="ophaal_plaats">
<p>Plaats: <?php echo $product->ophaal_plaats; ?></p>
</div>
<div class="aangeboden_door">
<p>
<table>
<?php
foreach($userdetail_list as $row){ ?>
<tr>
<td><?php echo $row->voornaam;?></td>
</tr>
<?php } ?>
</table>
</p>
</div>
<div class="status">
</div>
</div>
<a href="<?php echo base_url() ?>/KdGwController/details_bewerken/<?php echo $product->product_id; ?>">
<input type="button" class="btn btn-default cb" value="Cadeau bewerken">
</a>
</div>
<?php } ?>
Upvotes: 0
Reputation: 2408
You need to change your query as follows
function getdata($user_id){
$this->db->select("products.*,users.*");
$this->db->from('products');
$this->db->join('users','users.user_id = products.user_id','left');
$this->db->where('users.user_id', $user_id);
$query = $this->db->get();
return $query->result();
}
Upvotes: 1
Reputation: 305
I hope you should declare foreach loop correctly.
<?php foreach($products as $product) {
// print here the product info
}
?>
Upvotes: 2