News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

IP Ranges

Started by Luis-, February 25, 2018, 03:25:45 PM

Previous topic - Next topic

Luis-

Hey!

Basically I have a code that allows me to submit an IP address and return information from that IP address.

What I want to do is return all the rows that have the IP range that I submit.

Take this query as an example;
SELECT * FROM ip_address WHERE IP BETWEEN '123.45.0.0' AND '123.45.255.255'
Let's say I submit 192.168.0.1, i'd like to return every IP that has 192.168.0.x

turtlemanmike

Will the LIKE statement work here - LIKE "%192.123..12%"

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Sir Osis of Liver

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

albertlast

Just for the records,
in smf 2.1 the solution would be:

$smcFunc['db_query']('','
SELECT *
FROM ip_address
WHERE ip BETWEEN {inet:start_ip} and {inet:end_ip}',
array(
  'start_ip' => '123.45.0.0',
  'end_ip' => '123.45.255.255',
)


But works only when you use the inet field type from smf2.1.

Advertisement: