0

我正在尝试制作彩票游戏的搜索形式。我的目的是让表格找到所有抽出的 15 个数字中有 12 个相等的游戏。

我制作了一个表格,但它不起作用,因为它显示了所有包含至少 1 个成功结果的游戏。

我只想出现在每次抽签中匹配 12 个号码的游戏。

sql 文件只包含两行 id 和 numbers:

如果不存在 `lotto_table` 则创建表(
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `数字`文本不为空,
  主键(`id`)
) 引擎=MyISAM 默认字符集=latin1 AUTO_INCREMENT=4 ;

--
-- Extraindo dados da tabela `lotto_table`
--

插入`lotto_table`(`id`,`numbers`)值
(3, '01, 04, 06, 07, 08, 09, 10, 11, 12, 14, 16, 17, 20, 23, 24'),
(4, '01, 02, 04, 05, 08, 10, 12, 13, 16, 17, 18, 19, 23, 24, 25'),
(5, '01, 02, 04, 08, 09, 11, 12, 13, 15, 16, 19, 20, 23, 24, 25'),
(6, '01, 02, 04, 05, 06, 07, 10, 12, 15, 16, 17, 19, 21, 23, 25'),
(7, '01, 04, 07, 08, 10, 12, 14, 15, 16, 18, 19, 21, 22, 23, 25'),
(8, '01, 05, 06, 08, 09, 10, 13, 15, 16, 17, 18, 19, 20, 22, 25'),
(9, '03, 04, 05, 09, 10, 11, 13, 15, 16, 17, 19, 20, 21, 24, 25'),
(10, '02, 03, 04, 05, 06, 08, 09, 10, 11, 12, 14, 19, 20, 23, 24'),
(11, '02, 06, 07, 08, 09, 10, 11, 12, 16, 19, 20, 22, 23, 24, 25'),
(12, '01, 02, 04, 05, 07, 08, 09, 10, 11, 12, 14, 16, 17, 24, 25'),
(13, '03, 05, 06, 07, 08, 09, 10, 11, 13, 14, 15, 16, 17, 19, 23'),
(14, '01, 02, 05, 06, 07, 09, 13, 14, 15, 18, 19, 20, 21, 23, 25'),
(15, '01, 02, 04, 06, 08, 10, 12, 15, 16, 18, 19, 21, 23, 24, 25'),
(16, '02, 05, 06, 07, 08, 10, 12, 13, 15, 17, 19, 21, 23, 24, 25'),
(17, '01, 02, 03, 05, 06, 07, 09, 13, 14, 16, 17, 18, 19, 20, 21'),
(18, '02, 06, 07, 08, 10, 11, 14, 15, 17, 18, 19, 20, 22, 23, 24'),
(19, '02, 05, 06, 07, 08, 10, 11, 13, 14, 15, 16, 17, 20, 23, 24'),
(20, '03, 04, 06, 07, 08, 09, 10, 14, 16, 17, 18, 19, 20, 23, 24'),
(21, '01, 02, 04, 05, 08, 11, 14, 16, 18, 19, 20, 22, 23, 24, 25'),
(22, '01, 02, 03, 04, 05, 06, 07, 09, 10, 12, 13, 14, 15, 22, 25'),
(23, '01, 03, 04, 05, 06, 08, 10, 11, 12, 14, 16, 17, 18, 19, 20'),
(24, '01, 02, 03, 05, 07, 10, 11, 14, 17, 19, 20, 21, 23, 24, 25'),
(25, '01, 02, 03, 04, 05, 06, 07, 09, 13, 14, 16, 20, 22, 23, 24'),
(26, '05, 07, 08, 09, 10, 11, 13, 14, 16, 17, 19, 20, 21, 22, 23'),
(27, '03, 06, 08, 10, 11, 12, 13, 14, 15, 18, 20, 21, 22, 24, 25'),
(28, '01, 03, 07, 09, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21'),
(29, '01, 04, 05, 06, 08, 09, 13, 14, 16, 17, 19, 20, 21, 22, 24'),
(30, '01, 02, 03, 04, 06, 07, 08, 11, 14, 17, 19, 20, 21, 22, 23'),
(31, '01, 02, 03, 04, 09, 13, 14, 15, 17, 19, 20, 21, 22, 24, 25'),
(32, '01, 02, 04, 06, 07, 09, 10, 11, 14, 15, 16, 17, 20, 22, 23'),
(33, '01, 02, 05, 07, 08, 10, 11, 12, 14, 16, 19, 20, 21, 23, 24'),
(34, '01, 02, 04, 07, 08, 09, 10, 11, 15, 16, 18, 19, 20, 21, 23'),
(35, '01, 04, 05, 06, 11, 12, 13, 14, 16, 17, 19, 21, 22, 23, 25'),
(36, '01, 04, 05, 07, 08, 10, 11, 14, 17, 19, 20, 21, 22, 23, 24'),
(37, '01, 03, 04, 05, 08, 09, 10, 11, 13, 15, 20, 21, 22, 23, 24'),
(38, '01, 02, 03, 06, 07, 08, 09, 10, 13, 14, 15, 16, 22, 24, 25'),
(39, '02, 07, 08, 09, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 24'),
(40, '01, 02, 05, 07, 08, 10, 12, 13, 14, 16, 17, 20, 21, 22, 24'),
(41, '02, 03, 04, 09, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23, 25'),
(42, '01, 03, 04, 05, 06, 08, 11, 12, 14, 15, 17, 21, 22, 24, 25'),
(43, '01, 03, 06, 07, 08, 09, 10, 14, 17, 18, 19, 20, 22, 23, 24'),
(44, '03, 04, 05, 06, 10, 11, 12, 13, 14, 18, 19, 21, 23, 24, 25'),
(45, '01, 02, 03, 05, 07, 09, 14, 16, 17, 18, 19, 21, 23, 24, 25'),
(46, '01, 02, 04, 05, 06, 08, 10, 11, 14, 18, 19, 21, 23, 24, 25'),
(47, '01, 02, 03, 04, 05, 06, 08, 10, 11, 13, 15, 18, 20, 22, 25'),
(48, '02, 05, 06, 07, 11, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23'),
(49, '02, 04, 05, 06, 08, 11, 13, 15, 16, 19, 20, 21, 22, 23, 24'),
(50, '01, 02, 03, 06, 07, 09, 10, 11, 12, 13, 19, 20, 21, 23, 25');

搜索表格:

<html>
<head>
    <title>Search the Database</title>
</head>

<body>

<form action="search.php" method="post">
 Search:
 <input type="text" name="num1" />,
 <input type="text" name="num2" />,
 <input type="text" name="num3" />,
 <input type="text" name="num4" />,
 <input type="text" name="num5" />,
 <input type="text" name="num6" />,
 <input type="text" name="num7" />,
 <input type="text" name="num8" />,
 <input type="text" name="num9" />,
 <input type="text" name="num10" />,
 <input type="text" name="num11" />,
 <input type="text" name="num12" />,<br />
<input type="submit" name="submit" value="Submit" />
</form>


</body>

4

3 回答 3

2

如果数字序列很重要,最好将每个具有一个 id 的数字放在不同的列中,如下所示:

CREATE TABLE IF NOT EXISTS `lotto_table` (
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `n1` int(4) NOT NULL,
  `n2` int(4) NOT NULL,
  `n3` int(4) NOT NULL,
  `n4` int(4) NOT NULL,
  `n5` int(4) NOT NULL,
  `n6` int(4) NOT NULL,
  `n7` int(4) NOT NULL,
  `n8` int(4) NOT NULL,
  `n9` int(4) NOT NULL,
  `n10` int(4) NOT NULL,
  `n11` int(4) NOT NULL,
  `n12` int(4) NOT NULL,
  `n13` int(4) NOT NULL,
  `n14` int(4) NOT NULL,
  `n15` int(4) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 

然后放数据:

INSERT INTO `lotto_table` (`n1`,`n2`,`n3`,`n4`,`n5`,`n6`,`n7`,`n8`,`n9`,`n10`,`n11`,`n12`,`n13`,`n14`,`n15`) 
VALUES
(01, 04, 06, 07, 08, 09, 10, 11, 12, 14, 16, 17, 20, 23, 24),
(01, 02, 04, 05, 08, 10, 12, 13, 16, 17, 18, 19, 23, 24, 25),
(01, 02, 04, 08, 09, 11, 12, 13, 15, 16, 19, 20, 23, 24, 25),
(01, 02, 04, 05, 06, 07, 10, 12, 15, 16, 17, 19, 21, 23, 25),
(01, 04, 07, 08, 10, 12, 14, 15, 16, 18, 19, 21, 22, 23, 25),
(01, 05, 06, 08, 09, 10, 13, 15, 16, 17, 18, 19, 20, 22, 25),
(03, 04, 05, 09, 10, 11, 13, 15, 16, 17, 19, 20, 21, 24, 25),
(02, 03, 04, 05, 06, 08, 09, 10, 11, 12, 14, 19, 20, 23, 24),
(02, 06, 07, 08, 09, 10, 11, 12, 16, 19, 20, 22, 23, 24, 25),
(01, 02, 04, 05, 07, 08, 09, 10, 11, 12, 14, 16, 17, 24, 25),
(03, 05, 06, 07, 08, 09, 10, 11, 13, 14, 15, 16, 17, 19, 23),
(01, 02, 05, 06, 07, 09, 13, 14, 15, 18, 19, 20, 21, 23, 25),
(01, 02, 04, 06, 08, 10, 12, 15, 16, 18, 19, 21, 23, 24, 25),
(02, 05, 06, 07, 08, 10, 12, 13, 15, 17, 19, 21, 23, 24, 25),
(01, 02, 03, 05, 06, 07, 09, 13, 14, 16, 17, 18, 19, 20, 21),
(02, 06, 07, 08, 10, 11, 14, 15, 17, 18, 19, 20, 22, 23, 24),
(02, 05, 06, 07, 08, 10, 11, 13, 14, 15, 16, 17, 20, 23, 24),
(03, 04, 06, 07, 08, 09, 10, 14, 16, 17, 18, 19, 20, 23, 24),
(01, 02, 04, 05, 08, 11, 14, 16, 18, 19, 20, 22, 23, 24, 25),
(01, 02, 03, 04, 05, 06, 07, 09, 10, 12, 13, 14, 15, 22, 25),
(01, 03, 04, 05, 06, 08, 10, 11, 12, 14, 16, 17, 18, 19, 20),
(01, 02, 03, 05, 07, 10, 11, 14, 17, 19, 20, 21, 23, 24, 25),
(01, 02, 03, 04, 05, 06, 07, 09, 13, 14, 16, 20, 22, 23, 24),
(05, 07, 08, 09, 10, 11, 13, 14, 16, 17, 19, 20, 21, 22, 23),
(03, 06, 08, 10, 11, 12, 13, 14, 15, 18, 20, 21, 22, 24, 25),
(01, 03, 07, 09, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21),
(01, 04, 05, 06, 08, 09, 13, 14, 16, 17, 19, 20, 21, 22, 24),
(01, 02, 03, 04, 06, 07, 08, 11, 14, 17, 19, 20, 21, 22, 23),
(01, 02, 03, 04, 09, 13, 14, 15, 17, 19, 20, 21, 22, 24, 25),
(01, 02, 04, 06, 07, 09, 10, 11, 14, 15, 16, 17, 20, 22, 23),
(01, 02, 05, 07, 08, 10, 11, 12, 14, 16, 19, 20, 21, 23, 24),
(01, 02, 04, 07, 08, 09, 10, 11, 15, 16, 18, 19, 20, 21, 23),
(01, 04, 05, 06, 11, 12, 13, 14, 16, 17, 19, 21, 22, 23, 25),
(01, 04, 05, 07, 08, 10, 11, 14, 17, 19, 20, 21, 22, 23, 24),
(01, 03, 04, 05, 08, 09, 10, 11, 13, 15, 20, 21, 22, 23, 24),
(01, 02, 03, 06, 07, 08, 09, 10, 13, 14, 15, 16, 22, 24, 25),
(02, 07, 08, 09, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 24),
(01, 02, 05, 07, 08, 10, 12, 13, 14, 16, 17, 20, 21, 22, 24),
(02, 03, 04, 09, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23, 25),
(01, 03, 04, 05, 06, 08, 11, 12, 14, 15, 17, 21, 22, 24, 25),
(01, 03, 06, 07, 08, 09, 10, 14, 17, 18, 19, 20, 22, 23, 24),
(03, 04, 05, 06, 10, 11, 12, 13, 14, 18, 19, 21, 23, 24, 25),
(01, 02, 03, 05, 07, 09, 14, 16, 17, 18, 19, 21, 23, 24, 25),
(01, 02, 04, 05, 06, 08, 10, 11, 14, 18, 19, 21, 23, 24, 25),
(01, 02, 03, 04, 05, 06, 08, 10, 11, 13, 15, 18, 20, 22, 25),
(02, 05, 06, 07, 11, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23),
(02, 04, 05, 06, 08, 11, 13, 15, 16, 19, 20, 21, 22, 23, 24),
(01, 02, 03, 06, 07, 09, 10, 11, 12, 13, 19, 20, 21, 23, 25);

因此您可以创建查询以将每一列与输入数字相匹配

SELECT * FROM lotto_table WHERE
   n1=$num1 AND
   n2=$num2 AND
   ....
   ....
   n11=$num11 AND
   n12=$num12;

或为每个输入数字和 concat 操作创建一个 PHP 循环,以编程方式构建查询字符串

于 2018-01-31T07:08:27.350 回答
1

不要以这种方式存储数字,为每个数字使用单独的行,并制作numeros整数数据类型。

然后一个简单的GROUP BY查询会给你答案。

因此,您的第一行数据将改为:

id    number
3    1
3    4
3    6
3    7
3    8
3    9
3    10
3    11
3    12
3    14
3    16
3    17
3    20
3    23
3    24

一个示例查询是:

select id
from lotto_table
where number in (1,4,6,7,8,9,10,11,12,14,16,17)
group by id
having count(*) = 12
于 2012-10-17T18:54:32.600 回答
1

sql应该是这样的吧?

(1, 2, 3, 5, 6, 9, 10, 11, 13, 14, 16, 18, 20, 23, 24, 25),
(2, 1, 4, 5, 6, 7, 9, 11, 12, 13, 15, 16, 19, 20, 23, 24),
(3, 1, 4, 6, 7, 8, 9, 10, 11, 12, 14, 16, 17, 20, 23, 24),
(4, 1, 2, 4, 5, 8, 10, 12, 13, 16, 17, 18, 19, 23, 24, 25),
(5, 1, 2, 4, 8, 9, 11, 12, 13, 15, 16, 19, 20, 23, 24, 25),
(6, 1, 2, 4, 5, 6, 7, 10, 12, 15, 16, 17, 19, 21, 23, 25),
(7, 1, 4, 7, 8, 10, 12, 14, 15, 16, 18, 19, 21, 22, 23, 25),
(8, 1, 5, 6, 8, 9, 10, 13, 15, 16, 17, 18, 19, 20, 22, 25),
(9, 3, 4, 5, 9, 10, 11, 13, 15, 16, 17, 19, 20, 21, 24, 25),
(10, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 14, 19, 20, 23, 24),
(11, 2, 6, 7, 8, 9, 10, 11, 12, 16, 19, 20, 22, 23, 24, 25),
(12, 1, 2, 4, 5, 7, 8, 9, 10, 11, 12, 14, 16, 17, 24, 25),
(13, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 23),
(14, 1, 2, 5, 6, 7, 9, 13, 14, 15, 18, 19, 20, 21, 23, 25),
(15, 1, 2, 4, 6, 8, 10, 12, 15, 16, 18, 19, 21, 23, 24, 25),
(16, 2, 5, 6, 7, 8, 10, 12, 13, 15, 17, 19, 21, 23, 24, 25),
(17, 1, 2, 3, 5, 6, 7, 9, 13, 14, 16, 17, 18, 19, 20, 21),
(18, 2, 6, 7, 8, 10, 11, 14, 15, 17, 18, 19, 20, 22, 23, 24),
(19, 2, 5, 6, 7, 8, 10, 11, 13, 14, 15, 16, 17, 20, 23, 24),
(20, 3, 4, 6, 7, 8, 9, 10, 14, 16, 17, 18, 19, 20, 23, 24),
(21, 1, 2, 4, 5, 8, 11, 14, 16, 18, 19, 20, 22, 23, 24, 25),
(22, 1, 2, 3, 4, 5, 6, 7, 9, 10, 12, 13, 14, 15, 22, 25),
(23, 1, 3, 4, 5, 6, 8, 10, 11, 12, 14, 16, 17, 18, 19, 20),
(24, 1, 2, 3, 5, 7, 10, 11, 14, 17, 19, 20, 21, 23, 24, 25),
(25, 1, 2, 3, 4, 5, 6, 7, 9, 13, 14, 16, 20, 22, 23, 24),
(26, 5, 7, 8, 9, 10, 11, 13, 14, 16, 17, 19, 20, 21, 22, 23),
(27, 3, 6, 8, 10, 11, 12, 13, 14, 15, 18, 20, 21, 22, 24, 25),
(28, 1, 3, 7, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21),
(29, 1, 4, 5, 6, 8, 9, 13, 14, 16, 17, 19, 20, 21, 22, 24),
(30, 1, 2, 3, 4, 6, 7, 8, 11, 14, 17, 19, 20, 21, 22, 23),
(31, 1, 2, 3, 4, 9, 13, 14, 15, 17, 19, 20, 21, 22, 24, 25),
(32, 1, 2, 4, 6, 7, 9, 10, 11, 14, 15, 16, 17, 20, 22, 23),
(33, 1, 2, 5, 7, 8, 10, 11, 12, 14, 16, 19, 20, 21, 23, 24),
(34, 1, 2, 4, 7, 8, 9, 10, 11, 15, 16, 18, 19, 20, 21, 23),
(35, 1, 4, 5, 6, 11, 12, 13, 14, 16, 17, 19, 21, 22, 23, 25),
(36, 1, 4, 5, 7, 8, 10, 11, 14, 17, 19, 20, 21, 22, 23, 24),
(37, 1, 3, 4, 5, 8, 9, 10, 11, 13, 15, 20, 21, 22, 23, 24),
(38, 1, 2, 3, 6, 7, 8, 9, 10, 13, 14, 15, 16, 22, 24, 25),
(39, 2, 7, 8, 9, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 24),
(40, 1, 2, 5, 7, 8, 10, 12, 13, 14, 16, 17, 20, 21, 22, 24),
(41, 2, 3, 4, 9, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23, 25),
(42, 1, 3, 4, 5, 6, 8, 11, 12, 14, 15, 17, 21, 22, 24, 25),
(43, 1, 3, 6, 7, 8, 9, 10, 14, 17, 18, 19, 20, 22, 23, 24),
(44, 3, 4, 5, 6, 10, 11, 12, 13, 14, 18, 19, 21, 23, 24, 25),
(45, 1, 2, 3, 5, 7, 9, 14, 16, 17, 18, 19, 21, 23, 24, 25),
(46, 1, 2, 4, 5, 6, 8, 10, 11, 14, 18, 19, 21, 23, 24, 25),
(47, 1, 2, 3, 4, 5, 6, 8, 10, 11, 13, 15, 18, 20, 22, 25),
(48, 2, 5, 6, 7, 11, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23),
(49, 2, 4, 5, 6, 8, 11, 13, 15, 16, 19, 20, 21, 22, 23, 24),
(50, 1, 2, 3, 6, 7, 9, 10, 11, 12, 13, 19, 20, 21, 23, 25),

我拥有的搜索表单是:

<?php
mysql_connect ("localhost", "user","pass")  or die (mysql_error());
mysql_select_db ("database");

$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$num3 = $_POST['num3'];
$num4 = $_POST['num4'];
$num5 = $_POST['num5'];
$num6 = $_POST['num6'];
$num7 = $_POST['num7'];
$num8 = $_POST['num8'];
$num9 = $_POST['num9'];
$num10 = $_POST['num10'];
$num11 = $_POST['num11'];
$num12 = $_POST['num11'];

$sql = mysql_query("select * from lotto_table where numbers like '%$num1%' AND numbers like '%$num2%' AND numbers like '%$num3%' AND numbers like '%$num4%' AND numbers like '%$num5%' AND numbers like '%$num6%' AND numbers like '%$num7%' AND numbers like '%$num8%' AND numbers like '%$num9%' AND numbers like '%$num10%' AND numbers like '%$num11%' AND numbers like '%$num12%'");

while ($row = mysql_fetch_array($sql)){
    echo 'Game: '.$row['id'];
    echo '<br/> Numbers: '.$row['numbers'];
    echo '<br/><br/>';
    }

?>
于 2012-10-19T12:17:22.587 回答