[PHP] Re: Sessions: Basic Information

2004-12-03 Thread Lordo
Thanks alot.

Lordo


Peter Lauri [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Sessions will make you life easier if you are using cookies to control a
web
 session. http://th.php.net/manual/en/ref.session.php will give you most
 information regarding this, together with some examples. Play around with
 simple own examples and you will learn to work with sessions relativly
fast.

 /Peter


 Lordo [EMAIL PROTECTED] skrev i meddelandet
 news:[EMAIL PROTECTED]
  I have not yet worked with sessions and I don't know why I DO NOT WANT
to
  understand it!! :)) I am a traditional ASPer and I am addicted to
cookies.
  But I want to use sessions if they will make life easier for me.
 
  Can someone please direct me to an easy to understand resource with
 working
  samples? Thanks.
 
  Lordo

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Too many DELETE statements

2004-12-02 Thread Lordo
Thanks alot. You really gave me some good ideas.

Lordo


Richard Lynch [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 news.php.net wrote:
  I have 160,000+ members in my site. 40,000 of them have not logged in
  since
  2003 and they should be deleted. A member is not deleted from only one
  table. Based on user id, he should be deleted from 5 tables and also his
  photo, if any, should be unlink(ed).
 
  I tried to do that 10 by 10 using:

 Ah.  Don't do that.

 Do this:

 $query = delete from table1 where userid in (select userid from
 login_table where last_login = '2003-12-31');

 ANY time you are using PHP to loop through record after record after
 record in the database, and then you are sending a new query for every
 record you find, you DOING IT WRONG. :-)

 SQL is *VERY* good at describing exactly which records should have
 something done to them, and doing it, or finding them, or whatever.

 PHP is not so fast at that.

 Oh.  If your version of MySQL doesn't do sub-selects, you'll want to
do:

 $query = select userid from login_table where last_login =
'2003-12-31';
 $goners = mysql_query($query, $link) or trigger_error(@mysql_error($link)
 .  $query, E_USER_ERROR);
 $ids = array();
 while (list($userid) = @mysql_fetch_row($goners)){
   $ids[] = $userid;
 }
 $ids_sql = implode(, , $ids);

 $query = delete from table1 where userid in ($ids_sql);
 mysql_query($query, $link) or trigger_error(@mysql_error($link) . 
 $query, E_USER_ERROR);

 You can repeat that for each table.

 If it turns out that having 40K IDs in the array/string is too much, just
 add a LIMIT clause to the first query:

 $query = select userid from login_table where last_login = '2003-12-31'
 limit 100;

 You'll have to reload the page 40 times.  Or, better yet, once you're
 comfy with the page working for 100 peeps, just wrap a for($i = 0; $i 
 40; $i++) around the whole script.

 Needless to say, if you *DO* use the sub-select, you'll have to delete the
 records from the table that keeps track of last_login *LAST* :-)

 You may also want to archive the 40,000 users somewhere, just in case...

 Or even put them into a user_dormant table or something, so you can pull
 them back from the grave quickly if they want to re-activate their
 account.

 -- 
 Like Music?
 http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Too many DELETE statements

2004-12-02 Thread Lordo
Thanks. I will check the foreign key with cascading issue. But I have a
question: Will it have any bad effects on behavior? I have tables with
160,000, 400,000, etc. records.

Lordo

David Dickson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 news.php.net wrote:
  A member is not deleted from only one
  table. Based on user id, he should be deleted from 5 tables and also his
  photo, if any, should be unlink(ed).
 
  $query = delete from table1 where userid =  . $ID;
  $result = mysql_query($query, $link);
 
  $query = delete from table2 where userid =  . $ID;
  $result = mysql_query($query, $link);
 
  ...
 
  But even with only 10 members, the page takes 30-60 seconds to come back
to
  me. What is the best way to accomplish this? And it is possibe to delete
  1000 by 1000 or 100 by 100?

 This could be fixed by changing your database schema. You should have
 your main table, lets call it members, where userid is the primary key.
 All your other tables that use userid should reference members.userid as
 a foreign key with ON DELETE CASCADE set. This will make sure that any
 time a userid is deleted from members, the delete will cascade to all
 other tables that contain userid. See your databases documentation
 CREATE TABLE and ALTER TABLE syntax.

 -- David Dickson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Too many DELETE statements

2004-12-02 Thread Lordo
Thanks guys. I delete 500 by 500 now and it takes like 20 seconds only. I am
using the manual select where in method. It is great.

Now for the files, OK I will use a cron. But can I change the way I get the
file names? I mean instead of deleting the photo that is related to a
deleted member, can I delete photos that were last accessed a year ago?

Lordo

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Sessions: Basic Information

2004-12-02 Thread Lordo
I have not yet worked with sessions and I don't know why I DO NOT WANT to
understand it!! :)) I am a traditional ASPer and I am addicted to cookies.
But I want to use sessions if they will make life easier for me.

Can someone please direct me to an easy to understand resource with working
samples? Thanks.

Lordo

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php