converting ip to long string in mysql command !
Posted
by
Mac Taylor
on Stack Overflow
See other posts from Stack Overflow
or by Mac Taylor
Published on 2011-01-12T08:51:02Z
Indexed on
2011/01/12
8:53 UTC
Read the original article
Hit count: 164
hey guys
I'm trying to use ip2country technique to show my users'flags
simple thing to do is to write a sql statement and show users from session table and then query to see if their ip is in what range and show their flags
it simple but dengerous becuase when showing 300 users online and fetching from session table and then query once again ip2country table to get the flags there will be surelly memory overusage problem
now i wrote a query to make it in one query :
SELECT s.session_ip,ipc.* FROM session s
left join ip2country ipc ON ipc.ip_lo<=s.session_ip AND ipc.ip_hi>=s.session_ip
WHERE s.session_time > '".( time() - 60) )."'
now its clear above query is wrong cause ips saved in ip2country table is long string 1000013824 and ips saved in session table are real ip e.g. 193.169.0.0
now i know how to convert from ip to long in php ip2long() but is there any command in mysql to do it with out building another query !?
© Stack Overflow or respective owner