AbydosGater Posted November 4, 2006 Share Posted November 4, 2006 Hi, ive been working on a users online script,But i was wondering how owuld i go about if checking if the ip address was already in a row in the database? instead of making a new row everytime the user refreshs, how would i check if the users ip is already in the ip column, so that i could insert a new record or just update the old one?Thanks Abydos Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted November 4, 2006 Share Posted November 4, 2006 do a search on the database and see if there are any matches on the IP address. IF there are then don't add a new row. If you need more help let us know the table/field structure and we will go from there. Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 4, 2006 Author Share Posted November 4, 2006 Yeah but how would i go about searching the database? Quote Link to comment Share on other sites More sharing options...
Kelset Posted November 5, 2006 Share Posted November 5, 2006 Just run a query looking for that IP, just guessing here I'm a newb :($sql = "Select ip_col FROM TABLE WHERE ip='users_ip'";I take it your doing this through a login? Hope I was some helpCheers!Stephen Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 5, 2006 Share Posted November 5, 2006 well you have a table...obviously...this table stores the users IPs right and has how many times they have been to the site etc. well i am assuming your table layout is like this:id (int,11,auto_increment) | ip (varchar,255) | hits (int,11)1 125.15.73.9 142 125.15.73.2 1etc etc.aight... now. on your log file or whatever have this code.[code=php:0]$ip = $_SERVER['REMOTE_ADDR'];if(mysql_num_rows(mysql_query("SELECT * FROM table WHERE `ip`='".$ip."'")) == 0){//insert a new row etc.}else{//update the old row with +1 hits.}[/code] Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 5, 2006 Author Share Posted November 5, 2006 Perfect, genious, would never of thought of that!Thanks Quote Link to comment 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.