![]() |
|
#1
|
|||
|
|||
Need help with my databaseI am keeping track of visitors, their IP address, the last date visited, and the total number of times they have visited, in a Mysql database.
I have two parts to my script. One part is supposed to check to see if they have previously visited the site, and if so, update their date and number of visits. If the first part of the script does not locate them inside the database, then the other part of the script is supposed to add them to the database, set their visits at one, with todays date. I keep having problems with the script adding the visitor info multiple times, while its scrolling through the database. I have been struggling with this the last several days, multiple interations, and still no good. Any help would be greatfull. PHP Code:
|
|
#2
|
||||
|
||||
Re: Need help with my databaseI won't comment on the logic of what you're trying to do with this script, I will assume this is just an experiment.
ip2long - I haven't used this before, and now looking at the manual again, I remember why. Something from the manual, about this function: Quote:
Your first SQL query. You are fetching ALL the rows? Just to find ONE that matches? I think it's a waste of processing power and memory space. As your database grows - and it will - this script will not scale well. Instead, you should allow MySQL to handle the 'matching' since it is designed to do that really (REALLY) well. I would suggest something like this: PHP Code:
Please note that I am typing this without testing it. I don't have the (db) table and data to run it. Expect some (syntax) errors and typos. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
|||
|
|||
Re: Need help with my databaseThanks, worked first time, right out of the box.
I am self teaching myself MySql & PHP. So, I have difficulties trying to make certain things work, and that due to just lack of knowledge. I do appreceate your help. This script helps me keep track of visitors, where they hail from, and the number of times they stop by. Thanks. Richard |
|
#5
|
|||
|
|||
Re: Need help with my databaseI need help with a part of the above mentioned script.
This is part of the above mentioned script. if( $row[0] != date('Y-m-d') How does the ' $row[0] ' part of the script work. I have been searching, and have not had any luck finds any reference for this. Thanks, Richard |
|
#6
|
||||
|
||||
Re: Need help with my databaseI will try to explain. If I don't do a good job, please let me know.
Because the SQL was PHP Code:
$row[0] is the data (value) of `lastdate`. If the SQL was PHP Code:
Then the data (value) of `lastdate` would be inside $row[1]. $row is a numerically indexed array because of the mysql_fetch_row() function used in the example script. If we had used mysql_fetch_assoc(), then the line you asked about would look like this: PHP Code:
Read up on the following (3) functions, if you haven't already. They do the same thing basically... mysql_fetch_row() mysql_fetch_assoc() mysql_fetch_array() __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#7
|
|||
|
|||
Re: Need help with my databaseI now have another question concerning the script that you showed me. I am using the script, in the same form that you originally wrote. The only trouble that I am having, is every now and then I get duplicates in the database for the same IP address. Instead of updating the count associated with the IP address in the table, it inserts a new row.
I have been looking over the script, and unsure why its doing this. I am uploading a jpg of the table listing, and another copy of the script again: PHP Code:
|
|
#8
|
||||
|
||||
Re: Need help with my databaseI can't see anything wrong with the script. The only way an "INSERT" will happen is when a matching IP is not found. That should prevent duplicates.
Also, I am amazed that your (db) table actually let the "INSERT" happen at all! This is a symptom of a table that is not created very well. I would expect that the `ip_bin` column would be created as a PRIMARY KEY, refusing duplicates in any case. Describe the (db) table... And, why is this bit (see comments) still in the script? PHP Code:
|
|
#9
|
|||
|
|||
Re: Need help with my databaseActually there is no primary key for this table. I guess thats my problem.
Here is a picture of what the table looks like. |
|
#10
|
|||
|
|||
Re: Need help with my databasePHP Code:
Actually, that was part of the origional script, and I just didn't remove it. It's not affecting the script, so I guess I can just delete it now. |
Recent GIDBlog
Flickr uploads of IA pictures by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with Classes and database arrays | brookeville | C++ Forum | 1 | 13-Apr-2005 00:26 |
| Limit combo box and date time picker choice according to database created in folder | shinyhui | C++ Forum | 0 | 22-Feb-2005 20:16 |
| Limit combo box and date time picker choice according to database created in folder | shinyhui | MS Visual C++ / MFC Forum | 0 | 22-Feb-2005 02:13 |
| Limit combo box choice according to database created in folder | shinyhui | MS Visual C++ / MFC Forum | 3 | 21-Feb-2005 21:58 |
| cgi txt database to mysql | erhanharputlu | MySQL / PHP Forum | 0 | 27-Sep-2004 01:30 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The