在JQuery onchange文本字段中获取数据库数据

时间:2011-06-14 08:21:37

标签: mysql select concatenation

我很困惑如何决定在MySQL中采用的方式。

我有4个文本字段:

<input type="text" id="model">
<input type="text" id="number">
<input type="text" id="line">
<input type="text" id="date">

然后是数据库Detail_model中的表:

+---------+-----+-----------+-------------+-----------+
|Model    |Line |Date       |Startnumber  |Endnumber  |
+---------+-----+-----------+-------------+-----------+
|Bear     |X01  |2013-04-26 |098X0001     |098X0100   |
|Cat      |X02  |2013-03-10 |098x0201     |098X0300   |
+---------+-----+-----------+-------------+-----------+

如果我在id = model时输入Cat,在id = number时输入098x0003,我会得到结果:

Model        Line       Date
Cat          X02        2013-03-10

它在onchange期间的意思是我将参数Cat098X0003发送到MYSQL查询中。 TRY:

SELECT Model,Line, Date FROM Detail_model
WHERE Model LIKE 'Cat' AND .......(How to filter the number) ?

2 个答案:

答案 0 :(得分:2)

如果startnumber和endnumber是整数,你可以这样选择:

SELECT A.name,B.class, B.address FROM tableA AS A
LEFT JOIN tableB AS B
ON A.name = B.name
WHERE a.number >= b.startnumber AND a.number <= b.endnumber

答案 1 :(得分:2)

SELECT Model,Line, Date FROM Detail_model
WHERE Model LIKE 'Cat' AND Startnumber <= '098x0003' AND Endnumber >= '098X0003'

这就是我得到的结果。