SysAdm Posted January 24, 2008 Share Posted January 24, 2008 Basically, I have an entry in my database for a list of IP addresses, each time a page is viewed I want to get current IP, check it with the current list in the database. If not present, add it to the database and update another entry in the table as a counter. If present, do NOT update the other entry in the table. Like a UNIQUE PAGE VIEW that counts views. Here is what I have so far, but it does not work... error on mysql_fetch_array... I believe my variables are cross matching... plus, do I really need to get server IP twice???? Any help would be greatly appreciated... <code> // I have an entry in the table to store IPs (ad_ip) // and I have one for counting views (ad_views) $getip = $_server["REMOTE_ADDR"]; $check_ips = "select * from $ad_ip"; $ad_ip = mysql_query($check_ips); $check_ips = mysql_fetch_array($ad_ip); foreach($ad_ips as $ips) { $ip = $_server["REMOTE_ADDR"]; if($ip == $ips) { $s = "UPDATE $ads_tbl set ad_views=ad_views+0 where ad_id=$ad_id"; $result1=q($s); } else $s = "UPDATE $ads_tbl set ad_views=ad_views+1 where ad_id=$ad_id"; $result1=q($s); $ad_ip = "UPDATE $ads_tbl set ad_ip=$ip"; } </code> Quote Link to comment https://forums.phpfreaks.com/topic/87586-solved-unique-page-views-ip-address-in-database/ Share on other sites More sharing options...
revraz Posted January 24, 2008 Share Posted January 24, 2008 Check your Querries for errors and echo them. $ad_ip = mysql_query($check_ips) or die (mysql_error()); Do that to all your querries Quote Link to comment https://forums.phpfreaks.com/topic/87586-solved-unique-page-views-ip-address-in-database/#findComment-447972 Share on other sites More sharing options...
mraiur Posted January 24, 2008 Share Posted January 24, 2008 What is that $ad_ip. ? And from what i get from your discription. First u need to search for the existing IP. $cur_ip = $_SERVER['REMOTE_ADDR']; $query = " SELECT table.IP FROM table WHERE table.IP = '".$cur_ip."' ; $result = mysql_query($query); if(myslq_num_rows>0) { // ADD THE IP } else { // UPDATE... } sorry if i dont get what u needed. Quote Link to comment https://forums.phpfreaks.com/topic/87586-solved-unique-page-views-ip-address-in-database/#findComment-447980 Share on other sites More sharing options...
SysAdm Posted January 25, 2008 Author Share Posted January 25, 2008 O.k... changed my code to this: <code> $getip = $_SERVER['REMOTE_ADDR']; $check = mysql_query("SELECT * from $ad_ip where $ad_ip=$getip") or die (mysql_error()); </code> I have one entry in the table for a bogus ip:255.255.255.255... the script should compare my current IP: 4.235.251.244 to contents in the table... if there do A, if not do B.... Here's the error I get... ____________________ You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '255.255.255.255 where 255.255.255.255=4.235.251.244' at line 1 _____________________ This is really crazy... it appears to be pulling the right data from table and from my current IP, but it acts like it's NOT comparing them?????? Thanks in advance, this is killing me...!! Quote Link to comment https://forums.phpfreaks.com/topic/87586-solved-unique-page-views-ip-address-in-database/#findComment-448570 Share on other sites More sharing options...
SysAdm Posted January 25, 2008 Author Share Posted January 25, 2008 _________UPDATE!!!!______________ I think I'm on to something.... In MySQL I have a table named X and a FIELD named ad_ip in table X. But how do I add multiple entries into the ad_ip field?.. seems like the structure of my FIELD can only allow certain variable types, like VARCHAR, TEXT, DATE, CHAR, ETC, ETC... how do I setup the FIELD to allow a list of IP addresses???? Quote Link to comment https://forums.phpfreaks.com/topic/87586-solved-unique-page-views-ip-address-in-database/#findComment-448578 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.