converting ip to long string in mysql command !
- by Mac Taylor
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 !?