找到正确答案后,不要停下来

时间:2019-06-06 09:43:31

标签: asp-classic

到目前为止,我有一张桌子有六个记录。每个人都有2个字段:Min_lenght,Max_lenght。 这些字段定义了一个范围,因此第一项的最小值为Min_lenght = 160,最大值为Max_lenght = 179,依此类推。 当定义1个值(custom_lenght)时,我需要在此值在范围内时停止SQL。 因此(custom_lenght> Min_lenght)AND(custom_lenght

custom_lenght = cint(request("custom_lenght"))
Set objRS2 = Server.CreateObject("ADODB.Recordset")
sql2 = "SELECT * FROM tbl_model where Order by ID_model ASC"
objRS2.Open sql2, ConString
If Not objRS2.EOF Then
While Not objRS2.EOF
Min_lenght = cint(objRS2("Min_lenght"))
Max_lenght = cint(objRS2("Max_lenght"))
order = objRS2("order")
Price = objRS2("price") 
if (custom_lenght > Min_lenght ) AND (custom_lenght < Max_lenght) then
Outofrange="True"
else
Outofrange = "False"  
End If
objRS2.MoveNext
Wend
End If
PuliziaRS(objRS2)

问题是,SQL浏览了所有记录。我需要获取介于范围之间的商品的数据(价格和订单)

2 个答案:

答案 0 :(得分:1)

将您的SQL语句更改为$customfield=get_post_meta($post_id, 'custom_field', true);

这会将记录集限制为与您的custom_length相匹配的记录。

答案 1 :(得分:0)

作为替代;

custom_lenght = cint(request("custom_lenght"))
Set objRS2 = Server.CreateObject("ADODB.Recordset")
sql2 = "SELECT order, price FROM tbl_model WHERE " & custom_lenght & " BETWEEN Min_lenght AND Max_lenght Order by ID_model ASC"
objRS2.Open sql2, ConString
If Not objRS2.EOF Then
    order = objRS2("order")
    Price = objRS2("price")
    Outofrange = "True"
Else
    Outofrange = "False"  
End If
objRS2.Close