Jump to content

Call a function in a class


gsc1ugs

Recommended Posts

Hi

 

I'm new to PHP but not a complete novice but its not same as ASP, can I ask how a call a function from with a class?

 

my example code: I would like to call the function

 

repairCategories(0);

 

 

class MyClass

{

public function repairCategories($parent_id = 0) {

$query = $this->db->query("SELECT * FROM {category} WHERE parent_id = '" . (int)$parent_id . "'");

 

foreach ($query->rows as $category) {

// Delete the path below the current one

$this->db->query("DELETE FROM {category_path} WHERE category_id = '" . (int)$category['category_id'] . "'");

 

// Fix for records with no paths

$level = 0;

 

$query = $this->db->query("SELECT * FROM {category_path} WHERE category_id = '" . (int)$parent_id . "' ORDER BY level ASC");

 

foreach ($query->rows as $result) {

$this->db->query("INSERT INTO {category_path} SET category_id = '" . (int)$category['category_id'] . "', `path_id` = '" . (int)$result['path_id'] . "', level = '" . (int)$level . "'");

 

$level++;

}

 

$this->db->query("REPLACE INTO {category_path} SET category_id = '" . (int)$category['category_id'] . "', `path_id` = '" . (int)$category['category_id'] . "', level = '" . (int)$level . "'");

 

$this->repairCategories($category['category_id']);

}

}

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.