godsent Posted April 18, 2009 Share Posted April 18, 2009 OK here is what I'm trying to do. Where is row in my database with IP's which they are separated with space between. Ex: 127.0.0.1 127.0.0.2 127.0.0.3... And I'm trying to write function to check every row, and if in that row where is specified IP +1count. I mean to count how many rows have specified IP. Im not sure how can i do that: function countRows($ip) { $res = mysql_query("SELECT * FROM list WHERE ips = ?????"); $num_rows = mysql_num_rows($res); return $num_rows; } I have no idea how to do this, please help if you can. Quote Link to comment https://forums.phpfreaks.com/topic/154613-mysql-logic-question/ Share on other sites More sharing options...
haku Posted April 18, 2009 Share Posted April 18, 2009 mysql_query("SELECT count(ips) WHERE ips LIKE '%" . $ip_address . "%'"); Quote Link to comment https://forums.phpfreaks.com/topic/154613-mysql-logic-question/#findComment-813028 Share on other sites More sharing options...
fenway Posted April 20, 2009 Share Posted April 20, 2009 Hope those IP addresses are being stored numerically.... Quote Link to comment https://forums.phpfreaks.com/topic/154613-mysql-logic-question/#findComment-814574 Share on other sites More sharing options...
Mchl Posted April 20, 2009 Share Posted April 20, 2009 IP's which they are separated with space between. Ex: 127.0.0.1 127.0.0.2 127.0.0.3... It seems to me that they aren't. One field, multiple IPs stored as string... it doesn't get much worse than that. Quote Link to comment https://forums.phpfreaks.com/topic/154613-mysql-logic-question/#findComment-814580 Share on other sites More sharing options...
fenway Posted April 21, 2009 Share Posted April 21, 2009 Yikes. Quote Link to comment https://forums.phpfreaks.com/topic/154613-mysql-logic-question/#findComment-815878 Share on other sites More sharing options...
FezEvils Posted April 22, 2009 Share Posted April 22, 2009 $ip = 127.0.0.1 127.0.0.2 127.0.0.3 $ip_s= explode (" ",$ip); //it will remove the space then stored it into array echo $ip_s[0]; echo $ip_s[1]; echo $ip_s[2]; to count how may ip in $ip, use $result = count ($ip_s); Quote Link to comment https://forums.phpfreaks.com/topic/154613-mysql-logic-question/#findComment-816217 Share on other sites More sharing options...
Mchl Posted April 22, 2009 Share Posted April 22, 2009 Actually if we want to use MySQL for this, haku's solution would work. Quote Link to comment https://forums.phpfreaks.com/topic/154613-mysql-logic-question/#findComment-816327 Share on other sites More sharing options...
fenway Posted April 22, 2009 Share Posted April 22, 2009 Actually if we want to use MySQL for this, haku's solution would work. I'd prefer to "wrap" it in the delimeter too, but it's unlikely to be an issue for formatted data like IPs. Quote Link to comment https://forums.phpfreaks.com/topic/154613-mysql-logic-question/#findComment-816534 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.