Re: [PHP-DB] Re: About retrieving auto increment value
Hi, Thanks all, I will do it with php function. -- Marc Soler Marc Soler wrote: Hi I have the typical problem with retrieving auto increment value in php-mysql environment. I have search info in mysql page and I have found LAST_INSERT_ID() funtion but I don't know how to use correctly. I have one script that insert a row. And another script that must retrieve last auto_increment value for primary key on a table. I want something like this: SELECT LAST_INSERT_ID() FROM foo_table; (like curval(foo_sequence) in postgres) This doesn't work. It's possible? Where I am wrong? Thanks in advance I *think* you have to do this in the same script. I would suggest using mysql_insert_id() (in PHP) on the same page where you inserted and pass it into the page that needs it. -- paperCrane Justin Patrin -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] About retrieving auto increment value
LAST_INSERT_ID() is connection-based, not table-based. Therefore instead of: SELECT LAST_INSERT_ID() FROM foo_table you should do: SELECT LAST_INSERT_ID() HTH Ignatius _ - Original Message - From: Marc Soler [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, June 07, 2004 7:42 PM Subject: [PHP-DB] About retrieving auto increment value Hi I have the typical problem with retrieving auto increment value in php-mysql environment. I have search info in mysql page and I have found LAST_INSERT_ID() funtion but I don't know how to use correctly. I have one script that insert a row. And another script that must retrieve last auto_increment value for primary key on a table. I want something like this: SELECT LAST_INSERT_ID() FROM foo_table; (like curval(foo_sequence) in postgres) This doesn't work. It's possible? Where I am wrong? Thanks in advance -- Marc Soler -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: DISTINCT and multiple results...
Hi, maybe you're looking 4 something like this: select user , filename , count(filename) from table group by user,filename having count(filename) = 3 order by 1,2; Rui [EMAIL PROTECTED] writes: Hi there... I'm trying to create a MYSQL query that does the following... I've a table that lists ALL downloads from our site. so I may have the same user many times, but different files, or infact, same user, same file. What my boss wants to see is: If a user downloaded a file 3 times, she doesn't care, she just wants to see that it was downloaded. So I tried using DISTINCT(email), but then I loose the data about the other files that they've downloaded How can I create a query, where I can list only one instance of email, per multiple instatnces of a file name. Does that make sence? I'm reallyu stumped... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Count unique visits in PHP/MySQL
I am making a PHP/MySQL traffic report page from a table that records some user activity using PHP referrer information. I have a table with three rows: IP, page_name, and timestamp. The IP row records the user's IP address, page_name records the name of the page that the user loaded, and the timestamp row records in Unix timestamp format the time of day that the user requested the page. I want to be able to count unique visits per IP according to Internet Advertising Bureau standards, which count a Unique Visit as a log in by the same IP once every thirty minutes. IAB verbatim definition: Visit One or more text and/or graphics downloads from a site qualifying as at least one page, without 30 consecutive minutes of inactivity, which can be reasonably attributed to a single browser for a single session. A browser must pull text or graphics content to be considered a visit. So I need to make a MySQL query that will count how many times an IP logged a timestamp within a given time period. For example, the publisher checking traffic could request a date between May 1 and May 31, and I'd like to be able to return a page that counted unique users (count distinct IP), pages viewed (list distinct pages) and how many times they visited in that period. I have the first two down, but not the unique visits. Any ideas? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Count unique visits in PHP/MySQL
Here is how I would do: 1. Group your visits by IP, order them in time and give each row a sequential number starting with 1 (not completely trivial - exercise left to the reader) Now you have a temporary table T ( ip, timestamp, rank ) 2. Join the table to itself on two consecutive rows, and compute the timestamp difference between the rows (actually you must create a replica of the table because you can not self-join a temporary table) SELECT ip, SUM( IF( UNIX_TIMESTAMP( T.timestamp ) - UNIX_TIMESTAMP( U.timestamp ) = 60*30 0, 1 ) ) AS unik_visits FROM T LEFT JOIN U ONU.ip = T.ip AND U.rank = T.rank + 1 GROUP BY ip HTH Ignatius _ - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, June 08, 2004 5:03 PM Subject: [PHP-DB] Count unique visits in PHP/MySQL I am making a PHP/MySQL traffic report page from a table that records some user activity using PHP referrer information. I have a table with three rows: IP, page_name, and timestamp. The IP row records the user's IP address, page_name records the name of the page that the user loaded, and the timestamp row records in Unix timestamp format the time of day that the user requested the page. I want to be able to count unique visits per IP according to Internet Advertising Bureau standards, which count a Unique Visit as a log in by the same IP once every thirty minutes. IAB verbatim definition: Visit - One or more text and/or graphics downloads from a site qualifying as at least one page, without 30 consecutive minutes of inactivity, which can be reasonably attributed to a single browser for a single session. A browser must pull text or graphics content to be considered a visit. So I need to make a MySQL query that will count how many times an IP logged a timestamp within a given time period. For example, the publisher checking traffic could request a date between May 1 and May 31, and I'd like to be able to return a page that counted unique users (count distinct IP), pages viewed (list distinct pages) and how many times they visited in that period. I have the first two down, but not the unique visits. Any ideas? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php