A table with fields is displayed from the database:

<th><?php echo $this->lang->line('id'); ?></th> <th><?php echo $this->lang->line('title'); ?></th> <th><?php echo $this->lang->line('thumbnail'); ?></th> <th><?php echo $this->lang->line('category'); ?></th> <th><?php echo $this->lang->line('date_added'); ?></th> <th><?php echo $this->lang->line('views'); ?></th> <th><?php echo $this->lang->line('status'); ?></th> <th><?php echo $this->lang->line('actions'); ?></th> 

I want to do that by clicking on the link

 <td><a href="<?php echo base_url(); ?>videos/categories/<?php echo $video->cat_id; ?>" target="_blank"><?php echo $video->cat_name; ?></a></td> 

the table was sorted by the category column in the cat_id database

 т.е. SELECT * FROM `videos` ORDER BY `videos`.`cat_id` ASC LIMIT 0 , 30 

How to make a sorting request correctly so that the new window has a table with cat_id values?

  • open, please, your question, because I do not understand what you really want, because Your query SELECT * FROM videos ORDER BY videos . cat_id ASC LIMIT 0, 30 perfectly selects all cat_id figures, well, in general, everything that is in the table - Stanislav

2 answers 2

Perhaps you generally look the wrong way. Usually, if necessary, change the sort order of HTML tables, this is done without reloading the page, using JavaScript.

Here, for example, a plugin for jQuery, which helps to do it quite simply http://tablesorter.com/docs/

  • Thank. Great plugin, closes all questions ... - Serg888

replace link

 <a href="<?php echo base_url(); ?>videos/categories/<?php echo $video->cat_id; ?> 

on

 <a href="<?php echo base_url(); ?>videos/categories/<?php echo $video->cat_id . "?sort=asc"; ?> 

and request

 $query = "SELECT * FROM `videos` ORDER BY `videos`.`cat_id` ASC LIMIT 0 , 30"; 

on

 $sort =''; if (isset($_GET['sort'])) { $sort = 'ORDER BY videos.cat_id ASC'; } $query = "SELECT * FROM `videos` $sort LIMIT 0 , 30"; 
  • It does not display the category (cat_id) column from the database - in general ... The following columns simply moved to the category category. So far I have <td><a href="<?php echo base_url(); ?>videos/category/mypage.php?sort=cat_id" target="_blank"><?php echo $video->cat_name; ?></a></td> $sql = "SELECT * FROM videos"; if ($_GET['sort'] == 'cat_id') { $sql .= " ORDER BY cat_id"; this: <td><a href="<?php echo base_url(); ?>videos/category/mypage.php?sort=cat_id" target="_blank"><?php echo $video->cat_name; ?></a></td> $sql = "SELECT * FROM videos"; if ($_GET['sort'] == 'cat_id') { $sql .= " ORDER BY cat_id"; <td><a href="<?php echo base_url(); ?>videos/category/mypage.php?sort=cat_id" target="_blank"><?php echo $video->cat_name; ?></a></td> $sql = "SELECT * FROM videos"; if ($_GET['sort'] == 'cat_id') { $sql .= " ORDER BY cat_id"; - Serg888