How would you format a query on a MySQL database via PHP to find if an IP address falls between two numbers in two different fields?
Numerical representation of IP address to find:
1265631252
Database format:
IP FROM IP TO REGISTRY ASSIGNED CTRY CNTRY COUNTRY
"1265631232","1265893375","arin","1152835200","US","USA","United States"
"1265893376","1265958911","arin","1149120000","US","USA","United States"
"1265958912","1266024447","arin","1149120000","US","USA","United States"
"1266024448","1266089983","arin","1162425600","US","USA","United States"
The MySQL BETWEEN OperatorThe BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included.
Overview. Between query in MySQL or BETWEEN is a logical operator is used to select a range of values from the table of the database. Using between in a query, we can also check whether a value is in the provided range or not. BETWEEN operator first validates whether a record lies in the provided range or not.
MySQL DATEDIFF() Function The DATEDIFF() function returns the number of days between two date values.
Do a SELECT with a GROUP BY clause. Let's say name is the column you want to find duplicates in: SELECT name, COUNT(*) c FROM table GROUP BY name HAVING c > 1; This will return a result with the name value in the first column, and a count of how many times that value appears in the second.
A query like this:
SELECT * FROM your_table WHERE 1265631252 BETWEEN `IP FROM` AND `IP TO`;
Will return the row(s) for which the supplied number is between IP FROM
and IP TO
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With