douju9847 2015-07-07 19:06
浏览 35

SQL查询重复

I am actually facing a problem that I am unable to find out why is this happening, I've spent many hours but couldn't find any resolution, I would highly appreciate your help.

Well the case is:

I am pulling some COLUMNS from TRACKS table and those are order by two columns TRACKS.SPOTLIGHT and TRACKS.ID

Spotlight column only contains 1 or 0 values while tracks id's are 1,2,3,4 ... 500 all unique,

and they have a perpage limit of 20 records.

Now when I open up these records pull up correctly in the browser as I wanted the first 20 records show absolutely perfect and spotlight that has value 1 are on the top (that's what I wanted).

Now when I load more (next set of 20 records)

It is now repeating the spotlight track again + showing the rest track id's in DESC order.

The problem is I want to prevent the spotlight to repeat on every page loop.

Can someone help me with what I am doing wrong.

Thanks alot guys,

here is my code


    function searchTracks($start, $value) {
        // If the $start value is 0, empty the query;
        if($start == 0) {
            $start = '';
        } else {
            // Else, build up the query
            $start = 'AND tracks.id db->real_escape_string($start).'\'';
        }

        $query = sprintf("SELECT * FROM `tracks`, `users` WHERE (`tracks`.`title` 
    LIKE '%s' OR `tracks`.`description` LIKE '%s' OR `tracks`.`tag` LIKE '%s' OR 
    `tracks`.`record` LIKE '%s' ) AND `tracks`.`uid` = `users`.`idu` %s AND 
    `tracks`.`public` = 1 ORDER BY tracks.spotlight DESC, tracks.id DESC LIMIT 
    %s", '%'.$this->db->real_escape_string($value).'%', 
    '%'.$this->db->real_escape_string($value).'%', 
    '%'.$this->db->real_escape_string($value).'%', 
    '%'.$this->db->real_escape_string($value).'%', $start, ($this->per_page + 
    1));

        return $this->getTracks($query, 'searchTracks', '\''.$value.'\'');

    }

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 vmware exsi重置后的密码
    • ¥15 易盾点选的cb参数怎么解啊
    • ¥15 MATLAB运行显示错误,如何解决?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?
    • ¥15 电磁场的matlab仿真
    • ¥15 mars2d在vue3中的引入问题