Post by gsc1ugs » Fri Apr 10, 2015 10:04 pm

Hi

Can someone tell me whats wrong with this? I'm new to php but cant make this run, I'm tryng to reload ID's in category_to_path

Code: Select all

<?php

// Configuration
if (is_file('config.php')) {
	require_once('config.php');
}
// Startup
require_once(DIR_SYSTEM . 'startup.php');

// Registry
$registry = new Registry();

// Config
$config = new Config();
$registry->set('config', $config);

// Database
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);

class myclass{
   public function repairCategories($parent_id = 0) {
      $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category` WHERE `parent_id` = '" . (int)$parent_id . "'");

      foreach ($query->rows as $category) {
         // Delete the path below the current one
         $this->db->query("DELETE FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$category['category_id'] . "'");

         // Fix for records with no paths
         $level = 0;

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

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

            $level++;
         }

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

         $this->repairCategories($category['category_id']);
      }
   }
}
   $repair = new myclass();
   $repair->repairCategories(0);
?>

Active Member

Posts

Joined
Mon Sep 09, 2013 3:32 pm

Post by gsc1ugs » Tue Apr 14, 2015 11:39 pm

I'm new to php so a little help would be nice

Active Member

Posts

Joined
Mon Sep 09, 2013 3:32 pm

Post by gsc1ugs » Wed Apr 15, 2015 12:39 am

Can I convert this so its not calling object $this?

Code: Select all

<?php

// Configuration
if (is_file('config.php')) {
	require_once('config.php');
}
// Startup
require_once(DIR_SYSTEM . 'startup.php');

// Registry
$registry = new Registry();

// Config
$config = new Config();
$registry->set('config', $config);

// Database
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);
//repairCategories(0);

   function repairCategories($parent_id = 0)
   {
      $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category` WHERE `parent_id` = '" . (int)$parent_id . "'");
      print "SELECT * FROM `" . DB_PREFIX . "category` WHERE `parent_id` = '" . (int)$parent_id . "'";

      foreach ($query->rows as $category)
      {
         // Delete the path below the current one
         $this->db->query("DELETE FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$category['category_id'] . "'");

         // Fix for records with no paths
         $level = 0;

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

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

            $level++;
         }

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

         $this->repairCategories($category['category_id']);
      }
   }
   print "exit";
?>

Active Member

Posts

Joined
Mon Sep 09, 2013 3:32 pm
Who is online

Users browsing this forum: No registered users and 266 guests