ds08541 2019-01-11 07:31
浏览 78
已采纳

在php中使用数组和内爆函数的自定义查询

I am coding a game site. On this site, every question should be displayed to the user only once. Questions ID's are stored in a one field:

name of field in table: hidden_questions

hidden_questions values :1,2,3,17

I'm trying to get the IDs from the database and store them in an array using the implode function:

$q1= array($data['question_id']);
$q2= implode(',', $q1); // returns 1,2,3,4,5

And I want to display a non-repeat question using the following query:

$sql = "SELECT * FROM question WHERE question_id!=('".$q2."') LIMIT 1";

This code does not work and questions with the ID stored in the hidden_questions field are displayed. please guide me.

  • 写回答

1条回答 默认 最新

  • douzhenyu6533 2019-01-11 07:39
    关注

    I see that someone already wrote a comment about the solution, but I still write it down for you.

    You are on the right way and I understand what you want to do. But, MySQL does not have something like != in this syntax.

    Maybe you can try to use the NOT IN

    $sql = "SELECT * FROM question WHERE question_id NOT IN (".$b.") LIMIT 1";
    

    Also, why do you use the LIMIT 1? According to your explanation it looks like that you want to show multiple questions.

    Disclaimer: I did not test the code, maybe you needto play some with the quotes. But this should be the solution

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?