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 7600051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:48:57+00:00 2026-05-30T22:48:57+00:00

I have a MySQL DB field populated with some data. I have an option

  • 0

I have a MySQL DB field populated with some data. I have an option in my script which cleans that field so I can add new fresh data to it without appending to the old stuff.

However I am using a foreach loop which looks like this:

            foreach ($model->filenames as $key => $model->filename) {
            $model->get_title($model->filename);
            $model->get_showTitle($model->titles);
            $model->get_number($model->titles);
            $model->get_host($model->urls[$key]);
            $model->source_title($model->titles);
            $model->get_season();
            if ($model->show_exist_batch()) {
                $model->show_clean(); //the method in question
                $model->show_update();
            } else {
                $model->show_add();
                $model->twitter();
            }

The thing is that I want show_clean() to only run ONCE.
This is how show_clean() looks:

    public function show_clean() {
    if ($this->options->clean) {
        $query = "UPDATE jos_k2_items SET extra_fields = '', extra_fields_search = '' WHERE id = " . $this->item->id . "";
        $this->db->prepare($query);
        $this->db->query();
    }
}

$this->option->clean is set by a post variable in the constructor.

Are there any clever ways of doing this or do i need to do it the long way?

  • 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-30T22:48:59+00:00Added an answer on May 30, 2026 at 10:48 pm

    Not sure how “clever” this is, but its one way that doesn’t seem to be long.

    Set a variable outside of your loop indicating that you have not cleaned, and only call clean if it hasn’t been set yet. Once you clean the first, time, set your flag so it will not clean again.

    $cleaned = false;
    foreach ($model->filenames as $key => $model->filename) {
        // ...
        if ($model->show_exist_batch()) {
            if (!$cleaned) {
                $model->show_clean();
                $cleaned = true;
            }
            $model->show_update();
        } else {
            // ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table field set as time type which stores data in
I have a MySQL table which I want to populate with some dummy data
I have a MySQL table that has a field of comma separated values. How
I have a to match a field in MySQL, for which I thought I
Hi I have a field in mySql table called jobnumber which auto increments with
I have added a field in my MySQL Database, which is a DateTime field.
I have a table in MySQL 4.0 which currently has a year field as
I have a data table populated from a MySQL database via PHP. The first
I am using MYSQL. I have a varchar field which i incorrectly used for
I currently have a page defined which displays some data in rows. At the

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.