【问题标题】:mysql select query display in phpmysql 选择查询显示在 php
【发布时间】:2014-07-15 11:25:40
【问题描述】:

我有一个表名为:'paper' (question_bank)

            id  |  exam_id | question

            1   |  1       | What will be 35*9?
            2   |  1       | What will be 5-9?
            3   |  1       | A + B
            4   |  1       | What is a circle?
            5   |  1       | If we have four corners with equal height and width, then which shape is that?
            6   |  1       | What is Maths?
            7   |  1       | What is a triangle?
            21  |  1       | what is Nikhil surname?
            22  |  2       | Last name of Bhavesh is
            23  |  2       | Last name of Harsh is
            27  |  3       | What is Maths?
            28  |  3       | What is a triangle?
            30  |  3       | Last name of Harsh is

我有一个 php 页面,我必须在“paper”表中的“exam_id”“3”中添加问题。我插入问题的查询如下:

INSERT INTO paper (question exam_id) SELECT question, '3' FROM paper WHERE id = '2'
                        OR
INSERT INTO paper (question exam_id) SELECT question, '3' FROM paper WHERE id = '1'
                        OR

我还可以添加一个新问题,所以查询是:

INSERT INTO paper (question, exam_id) VALUES ('blah blah blah', '3')

这取决于我选择的问题或我添加的任何新问题。

现在,当我想从表'paper' 中向exam_id '3' 添加更多问题时,它会显示所有问题。我的选择查询如下:

SELECT * FROM paper WHERE exam_id != '3'

它显示所有问题,但例如我已经添加了 id = '23',所以我不希望在添加更多问题时显示该问题。请帮助我进行选择查询。如果我想念什么,请告诉我!提前致谢!

【问题讨论】:

  • 我不明白。您正在使用exam_id != 3 查询所有问题,但您不希望使用id=23 的问题?没有意义,因为后者满足您在 where 子句中给出的条件
  • 因为我已经在exam_id = 3 中添加了id = 23,所以我不想在向exam_id = 3 添加更多问题时显示该问题

标签: php database select mysqli


【解决方案1】:

我不确定我是否理解正确,但你可以列出你不想看到的问题的 ID。

例如:排除ids23、24、25

SELECT * FROM paper WHERE exam_id != 3 AND id NOT IN (23, 24, 25)

【讨论】:

  • ...或在数据库中引入一个标记,标记您想查看的内容,并且一切都由数据驱动
【解决方案2】:

好的,我明白了.....

我需要做的就是再次触发查询,以免重复之前选择的问题....

SELECT * FROM paper WHERE question = '$row['question']' AND exam_id = '3'
if($select)
{
    ************************* SHOW RESULT *********************
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多