Jump to content

[SOLVED] Unique page views... ip address in database...


Recommended Posts

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>

 

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.

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...!!

_________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????

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.