• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how i can to show specific record from a table

hi guys
how are you?
i have a question about, how can i show for example last 5 photo added in specific category

PHP Code:
<?php foreach ($projects as $item): ?>
                            <a href="<?php echo $item->image ?>">
                                <div class="gallery-item"><img src="<?php echo $item->image ?>" alt="<?php echo $item->title ?>"></div>
            <?php endforeach ?>

this code show all records/photos on the projects, i just want to show specific category.



This question has many answers depending on how you want it to work. Here are a few answers...
- You could have the query to only pull the last 5 photos from a specific category.
- You could still pull all the photos and have a filter which would allow the user to select specific photos by category

Your thoughts...

could you please show my an example, i'm not an expert.


(10-31-2018, 06:31 PM)king_ahwaz Wrote: could you please show my an example, i'm not an expert.


What needs to be done depends completely on how the table(s) are structured. So it's really hard to provide a complete and accurate example.

That being the case, I'll make some stuff up. The table "projects" has the following fields

"projID"  an auto incrementing integer and primary key for the table
"catID"  an integer representing various categories
"image" the actual image data
"title" a string

A model function could look something like this

PHP Code:
public function get_last_five($category)
->select('image, title')
           ->order_by('projID''DESC');  //reverse the natural sort order

   // get five rows starting at the first row
   $query $this->db->get_where('projects', array('catID' => $category), 50);
    // make sure that get_where worked - it will be false if it failed
   if($query !== FALSE)
      return $query->result();  //returns an array of "row" objects

The Query Builder documentation is HERE
and everything you need to know about generating query results is HERE.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.