Welcome Guest, Not a member yet? Register   Sign In
How can i make model query based on images
#4

This just requires a little prep-work in the controller to get the data into the form that makes it easiest to work with in the view:
PHP Code:
$leftarticle $this->model_front->lefttrend();
$rows = array();
$rows[] = $leftarticle->row_array(2);
$rows[] = $leftarticle->row_array(3);

// Alternatively, you could add a method to your model (or change the existing one)
// to only return the rows you need in the first place.

$data['rows'] = $rows

Then, in your view, you can loop through the array instead of creating multiple views:
PHP Code:
<?php foreach ($rows as $row) : ?>
<div class="col-lg-12 child-articles-trend">
    <img src='<?php echo base_url("uploads/article/{$row['art_image']}"); ?>' alt="<?php echo $row['art_title']; ?>" />
    <h4><a href='<?php echo base_url("trend-article/{$row['art_slug']}"); ?>'><?php echo $row['art_title']; ?></a></h4>
</div>
<?php endforeach; ?>

Or, if you don't want to use a foreach() inside your view, you can put a foreach() loop inside your controller and load the same view for each row:
PHP Code:
// $data['rows'] = $rows;

foreach ($rows as $row) {
    $data['row'] = $row;
    $this->load->view('your_view'$data);


Then 'your_view' would just be something like this:
PHP Code:
<div class="col-lg-12 child-articles-trend">
 
   <img src='<?php echo base_url("uploads/article/{$row['art_image']}"); ?>' alt="<?php echo $row['art_title']; ?>" />
 
   <h4><a href='<?php echo base_url("trend-article/{$row['art_slug']}"); ?>'><?php echo $row['art_title']; ?></a></h4>
</div> 
Reply


Messages In This Thread
RE: How can i make model query based on images - by mwhitney - 08-19-2015, 06:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB