select case request.querystring("order")
case "up"
strsql = "update story set orderField = orderField + 1 where orderField = "& request.querystring("orderField")-1 & " and ID = " & request.querystring("ID") & ";" &_
"update TABLE set orderField = orderField - 1 where PrimaryKeyId = " & request.querystring("PrimaryKeyId") & " and ID = " & request.querystring("ID")
updateDatabase(strsql)
case "down"
strsql = "update story set orderField = orderField - 1 where orderField = "& request.querystring("orderField")+1 & " and ID = " & request.querystring("ID") & ";" &_
"update TABLE set orderField = orderField + 1 where PrimaryKeyId = " & request.querystring("PrimaryKeyId") & " and ID = " & request.querystring("ID")
updateDatabase(strsql)
end select
<a href="&scriptName&"?order=up&ID="&ID&"&PrimaryKeyId="&PrimaryKeyId&"&orderField="&orderField&">up</a>
<a href="&scriptName&"?order=down&ID="&ID&"&PrimaryKeyId="&PrimaryKeyId&"&orderField="&orderField&">down</a>
Sometimes you need to think backwards.
Here was the problem. I needed to match up some IP address ranges to the company that owns them. Looking for a simple solution to the problem I came up with storing the IP address block patterns in the database as follows:
ip_pattern
----------------
127.%.%.%
192.168.%.%
10.%.%.%
Any idea why I choose % as the wildcard?
That's right - it's the wildcard operator in SQL for the LIKE statement.
So now when I have have an IP address 192.168.1.1, I can do what I like to call a backwards LIKE query:
SELECT company, ip_pattern
FROM company_blocks
WHERE '192.168.1.1' LIKE ip_pattern
This works on SQL Server and MySQL, and I would think it should work fine on any database server.