Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7606495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:25:22+00:00 2026-05-31T00:25:22+00:00

need some help figuring this out. My function: function cleanDatabase() { $allowedTime = $this->time

  • 0

need some help figuring this out.

My function:

function cleanDatabase()
{
    $allowedTime = $this->time - 10;
    $query = mysql_query("SELECT * FROM `chatsessions` WHERE `last_active` < ".$allowedTime." AND `public` = 0");
    if( mysql_num_rows($query) > 0 ){
        while($row = mysql_fetch_array($query)){
            //move messages to history for evrey cID
            $query2 = mysql_query(" SELECT * FROM `messages`, `chatsessions` 
                                    WHERE messages.cID = ".$row['cID']." 
                                    AND chatsessions.cID = messages.cID
                                    AND chatsessions.public = 0");
            if( mysql_num_rows($query2) > 0 ){
                while($row2 = mysql_fetch_array($query2)){
                    $insert = mysql_query("INSERT INTO `message_history` (`cID`, `mID`, `user_id`, `sender`, `sendtime`, `message`) VALUES 
                                          (".$row2['cID'].", ".$row2['mID'].", ".$row2['user_id'].", '".$row2['sender']."', ".$row2['sendtime'].", '".$row2['message']."')");

                    if($insert)
                        $delete = mysql_query("DELETE FROM `messages` WHERE `cID` = ".$row2['cID']);

                    if(!$delete)
                        return false;
                }
            }
            $query3 = mysql_query("DELETE FROM `chatsessions` WHERE `cID` = ".$row['cID']." AND public = 0");
        }
    }
}

The function does

  1. select unactive chats the are NOT public 1

  2. Fetch messages from the selected chat

  3. insert messages to history

  4. if inserted delete old messages

  5. delete chat sessions what dont have public = 1

What it needs to do:

  1. select unactive chats the are NOT public 1

  2. Select messages from cID when the last row with that cID is removed (public rows wont get removed so those messages should always stay)

  3. insert messages to history

  4. if inserted delete old messages

  5. delete chat sessions what dont have public = 1

The problem is there are multiple rows in chatsession with the same cID (one for every user and the permanent with pulbic=1 )
i dont know how to NOT delete messages IF there is a chatsession with that ID that has public = 1

edit: step 2 of how it should work

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:25:23+00:00Added an answer on May 31, 2026 at 12:25 am

    Just trying to understand your setup, you retrieve the cID from chatsessions, which would be either be public or private ( public = 1 or 0 ).

    Would the messages within the chatsession (cID) all be public or private, as they would inherit the properties from the chat session.

    Or is there the ability to have a public message broadcast from a private room (if this is the case – there is a subquery / 2nd statement you can run)

    EDIT:

    you could reduce the whole procedure and only use 2 sql statements (no loops) – something like

    function cleanDatabase() {
    $allowedTime = $this->time - 10;
    
    // update history
    $query = mysql_query("INSERT INTO `message_history` (`cID`, `mID`, `user_id`, `sender`, `sendtime`, `message`) SELECT messages.cID, messages.mID, messages.user_id, messages.sender, messages.sendtime, messages.message FROM `messages`, `chatsessions`  WHERE `last_active` < ".$allowedTime." AND chatsessions.cID = messages.cID AND chatsessions.public = 0");
    
    // delte old rows
    $query = mysql_query("DELETE FROM  `messages`, `chatsessions`  WHERE `last_active` < ".$allowedTime." AND chatsessions.cID = messages.cID AND chatsessions.public = 0");
    }
    

    I can test this better later, but should point you in the right direction?

    Mark

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help figuring this out. I am trying to create a function
I'm a n00b and I need some help figuring out this issue, I would
I need some help figuring out how to do something. I got this gallery
I am having an absolute headache figuring this out. I badly need some help
I need some help figuring out this for loop logic. I know exactly what
Need some php help in figuring out how use this array I created, but
I need some help from the shell-script gurus out there. I have a .txt
Hey all, i am in need of some help with figuring out how to
I need some help with figuring out Pythons *args and **kwargs . It's simple
I need help figuring out some regular expressions. I'm running the dig command and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.