mr.tanmay mr.tanmay - 9 months ago 64
MySQL Question

Images not coming id wise

There are 2/3 users in my database and in another table there are some pictures against each users.(Example:userA has img1,img2,img3 || UserB has imga,imgb,imgc).
when i trying to fetch data from database but with every profile image is showing but those images are from the last users .Meaning if userB is last user in database then at the time of display images everywhere the imges are showing are the images of userB.

Below are the codes:

Controller

public function index()
{
$this->load->model("Interior_listing_model","interior");
$data['articles'] = $this->interior->interior_list();
// $type_id = $this->input->get('score');
foreach ($data['articles'] as $article) {
$type_id = $article['type_id'];
$data['particles'] = $this->interior->image_list($type_id);
}

//echo($type_id);
// Load Interior Listing View
$this->load->view("interior/interior",$data);
}


Model

class Interior_listing_model extends CI_model
{
public function interior_list()
{
//$query = $this->db->get('interior_testing');
$query = $this->db->get_where('interior_testing', array('category_id' => 1),0,0);
return $query->result_array();

}
public function image_list($type_id)
{

$query = $this->db->get_where('interior_image_testing', array('type_id' => $type_id),3,0);
return $query->result_array();

}

}


view

<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link rel="stylesheet" href="assets/css/style.css"/> <!-- needs to be renamed -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

</head>

<body>
<div class="tophead">
<!--menu start-->
<nav>
<div class="custom_nav">
<div class="logoimg pull-left">
<a class="navbar-brand" href="#">
<img class="logo" src="assets/img/WhiteLogo.png">
</a>
</div>
<div id="menu_items" class="pull-right">
<a class="mobile_toggle_menu"><i class="fa fa-bars fa-2x"></i></a>
<ul>
<li><a href="#">Project</a></li>
<li><a href="#">How it works</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</nav>
<!--menu end-->
<!---writing start-->
<div class="text-center">
<h3>Find the right designer</h3>
</div>
<div class="text-center">
<a class="quote" href="<?php echo base_url('BluemasonsForm/registration'); ?>">Get Free Quote</a>
</div>
<!---writing end-->
</div>
<!-- The subview section starts here -->
<div class="container">
<!--Category start-->
<div class="text-center category">
<a class="catname activecat" href= "<?php echo base_url(''); ?>" >Interior</a>

<a class="catname" href="<?php echo base_url('welcome/architect'); ?>">Architect</a>
<!-- <a class="catname" href="#">Interior & Architect</a>-->
<!-- <a class="catname" href="#">Others</a>-->
</div>
<!--Category end-->
</div>
<!-- type your image fetching query here -->
<?php foreach($articles as $article): ?>

<!--###################################################################################-->
<!---listing section start-->
<div class="listing">
<div class="container">
<!---1st list start-->
<div class="row listelements">
<!---listing Profile strat-->
<div class="col-lg-3 col-12">
<div class="media">
<img class="d-flex mr-1 img-circle" src="assets/img/<?= $article['profile_pic'] ?>" alt="Profile Picture"> <!-- needs to be changed -->
<div class="media-body">
<h5 class="mt-0"><?= $article['name'] ?></h5>
<!--<input type="text" name="id" value="<?= $article->type_id ?>"> -->
<span class="text-center"><?= $article['type'] ?></span><br/>
<span class="text-center"><i class="fa fa-map-marker"></i>&nbsp; <?= $article['location'] ?></span><br/>
<span class="text-center"><i class="fa fa-phone"></i>&nbsp; Contact</span>
</div>
</div>
</div>

<!---listing Profile end-->
<!---Profile image start-->

<div class="col-lg-9 col-12">
<div class="row mobileimage">



<?php foreach($particles as $particle): ?>

<?php foreach($particle as $particle_one): ?>

<div class="col-lg-4 col-md-4 col-sm-4 col-6 workimg">
<img src="assets/img/<?= $particle_one['image_path'] ?> " width="100%">
</div>
<?php endforeach; ?>

<?php endforeach; ?>
<!--- View all strat-->
<div class="col-12">
<a class="viewall pull-right" href="<?php echo base_url("details/profile/".$article['type_id']); ?>">
View all
</a>
</div>
<!--- View all end-->
</div>
</div>

<!---Profile image end-->
</div>
<!---1st list end-->
</div>
</div>
<?php endforeach; ?>
<!-- Show more option-->
<div class="col-12">
<p class="text-center" id="load_more">
<a> Show more
<i class="fa fa-angle-double-down"></i>
</a>
</p>
</div>

<!---listing section end-->
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<script src="assets/js/custom.js"></script> <!-- needs to be renamed -->
</body>
</html>

Answer Source

Change your Controller code

public function index()
    {   
        $articles = array();
        $this->load->model("Interior_listing_model","interior");
        $articlesArray  = $this->interior->interior_list();
        // $type_id   = $this->input->get('score');
        foreach ($articlesArray as $article) {

            $article['images'] = $this->interior->image_list($article['type_id']);
            $articles[] = $article; 
        }

        $data['articles'] = $articles;
        // Load Interior Listing View
        $this->load->view("interior/interior",$data);
    }

Chagne your View code like

<!DOCTYPE html>
<html lang="en"> 
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    <link rel="stylesheet" href="assets/css/style.css"/> <!-- needs to be renamed -->
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

  </head>

  <body>
    <div class="tophead">
      <!--menu start-->
     <nav> 
      <div class="custom_nav">
        <div class="logoimg pull-left">
           <a class="navbar-brand" href="#">
             <img class="logo" src="assets/img/WhiteLogo.png">   
           </a>
        </div>
        <div id="menu_items" class="pull-right">
         <a class="mobile_toggle_menu"><i class="fa fa-bars fa-2x"></i></a>
         <ul>
          <li><a href="#">Project</a></li>   
            <li><a href="#">How it works</a></li>   
          <li><a href="#">Contact</a></li>   
         </ul>   
        </div>
      </div>
      </nav>
      <!--menu end-->
      <!---writing start-->
        <div class="text-center">
          <h3>Find the right designer</h3>
        </div>
        <div class="text-center">
          <a class="quote" href="<?php echo base_url('BluemasonsForm/registration'); ?>">Get Free Quote</a>
        </div>
      <!---writing end-->
    </div>
    <!-- The subview section starts here -->  
    <div class="container">
      <!--Category start-->
        <div class="text-center category">
           <a class="catname activecat" href= "<?php echo base_url(''); ?>" >Interior</a> 

           <a class="catname" href="<?php echo base_url('welcome/architect'); ?>">Architect</a>
<!--           <a class="catname" href="#">Interior & Architect</a>-->
<!--           <a class="catname" href="#">Others</a>-->
        </div>
      <!--Category end-->  
    </div>
    <!-- type your image fetching query here -->
    <?php foreach($articles as $article): ?>

    <!--###################################################################################-->
    <!---listing section start-->
    <div class="listing">
     <div class="container">
         <!---1st list start-->
       <div class="row listelements">
        <!---listing Profile strat-->
         <div class="col-lg-3 col-12">  
           <div class="media">
            <img class="d-flex mr-1 img-circle" src="assets/img/<?= $article['profile_pic'] ?>" alt="Profile Picture"> <!-- needs to be changed -->
              <div class="media-body">
                <h5 class="mt-0"><?= $article['name'] ?></h5>
                <!--<input type="text" name="id" value="<?= $article->type_id ?>"> --> 
                  <span class="text-center"><?= $article['type'] ?></span><br/>
                     <span class="text-center"><i class="fa fa-map-marker"></i>&nbsp; <?= $article['location'] ?></span><br/>
                  <span class="text-center"><i class="fa fa-phone"></i>&nbsp; Contact</span>
              </div>
            </div>
         </div> 

        <!---listing Profile end--> 
        <!---Profile image start-->

         <div class="col-lg-9 col-12">
           <div class="row mobileimage">



            <?php foreach($article['images'] as $particle): ?>



              <div class="col-lg-4 col-md-4 col-sm-4 col-6 workimg">
                <img src="assets/img/<?= $particle['image_path'] ?> " width="100%"> 
              </div> 

            <?php endforeach; ?>   
            <!--- View all strat-->
            <div class="col-12">
               <a class="viewall pull-right" href="<?php echo base_url("details/profile/".$article['type_id']); ?>">
                 View all  
               </a>   
            </div>    
           <!--- View all end-->
           </div>    
         </div>

        <!---Profile image end-->
        </div>
         <!---1st list end-->
      </div>
    </div>
    <?php endforeach; ?> 
    <!-- Show more option-->
    <div class="col-12">
      <p class="text-center" id="load_more">
          <a> Show more 
            <i class="fa fa-angle-double-down"></i>
          </a>
      </p>
    </div>

 <!---listing section end-->
    <!-- jQuery first, then Tether, then Bootstrap JS. -->
    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
    <script src="assets/js/custom.js"></script> <!-- needs to be renamed -->
  </body>
</html>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download