duanjiaopi8218 2014-04-21 23:14
浏览 26

如何在每个循环中使用关键字从MySQL获取新结果?

I'm new to MySQL, so I've gotten a bit confused here. What I'm doing right now is calling a Mysql query that fetches data from a table where a keyword is matched. The code is right here:

public function fetch_tags($tag) {
    global $pdo; 

    $query = $pdo->prepare("SELECT * FROM `articles`  WHERE `article_tags` LIKE '%$tag%' OR `article_content` LIKE '%$tag%'"); 

    $query->execute();

    return $query->fetch();
}

The problem is that say the keyword passed in first is "Michael", and then the next one is "Dekstra," both of these will return the exact same row because they are the first and last name of the same person. I don't want to fetch the same result twice though. How can I make it so that once a particular result has been fetched, the next query won't go in to get the same result again. They need to be different every single time. I want them ordered from newest to oldest.

Any help is much appreciated. I feel really lost.

  • 写回答

1条回答 默认 最新

  • dsx666666 2014-04-21 23:17
    关注

    Well you can add a $blacklist parameter, which will contain an array of IDs of rows already fetched and add it to your query: WHERE id NOT IN (1,2,3).

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集