Duplicate category names issue...

Bug Reporting and Feature Suggestions /Improvements go here.

Moderator: pgolovko

Duplicate category names issue...

Postby nucite » 05/23/2007 6:45 am

I set this (v1.3b) up at Nucite.net. Great script. Thanks for making it a freebie!

However, I came across an issue when I had two categories with the same name, but belonging to different parents. For example, here are two separate paths:

Main > Health > Reproductive Health > Birth Control
Main > Society > People > Women > Health

I could not get the links to show under the Birth Control category because it (within the index function) was assuming the parent id of Birth Control was Health category from the second path... which has no children.

Well, I fixed it. Within that admin function is a catch from all of the categories. If it finds the name from the parent it just assumes that is the parent. I altered it so that it would be added to an array of possible parents. I then looped over all of the possible parents and threw in an "OR" catch on the SQL query.

so now, that piece of the index function (on my implementation) looks like this:

Code: Select all
$parent_results = mysql_query("SELECT `id`, `path` FROM `categories`");
echo mysql_error();
$parent_id = "";
if(mysql_num_rows($parent_results)){
   while($parent_row = mysql_fetch_array($parent_results)){
      if($parent_row['path'] == $sub_path){
         $parent_id = $parent_row['id'];
         $possible_parents[] = $parent_row['id'];
      }
   }
}
if (count($possible_parents) > 0) {
   foreach ($possible_parents as $pid) {
      $parent_sql .= " `parent` = '$pid' OR ";
   }
   $length = strlen($parent_sql);
   $new = substr($parent_sql, 0, ($length - 3));
   $sql_add = " AND ($new)";
}
$sql = "SELECT `title`, `description`, `keywords`, `id` FROM `categories` WHERE `path` = '$path' $sql_add LIMIT 1";
$relusts = mysql_query($sql);

Hopefully this will help someone else too... or get into the next release.

- Jeff
nucite
 
Posts: 1
Joined: 05/23/2007 6:31 am


Postby gc_rjauregui » 05/23/2007 1:18 pm

Thanks!

I am going to move this over to development.
Best Regards,

Ryan Jauregui
geekcoders development member

laf innovative | development blog
User avatar
gc_rjauregui
Site Admin
 
Posts: 394
Joined: 03/25/2006 1:23 am
Location: Stanton, CA

Postby zudafrica » 06/22/2007 10:34 am

please forgive my ignorance - which file does this fix refer to?
zudafrica
 
Posts: 2
Joined: 06/22/2007 10:32 am

Postby zudafrica » 06/25/2007 4:03 am

:thumbleft: do'h functions.php :salute:
zudafrica
 
Posts: 2
Joined: 06/22/2007 10:32 am

Postby newbiz » 10/08/2007 12:18 pm

hi
this is my problem :
http://astanda.com/forums/viewtopic.php?p=1897#1897
when i changed the functions.php the problem not solved .
check this url : http://7xlink.com/Computer/Internet/
there is 338 link :-s but it's empty ,

maybe i didn't changed the functions.php correctly !
please someone attach or send the new edition of functions.php to me .

Thank you .
newbiz
 
Posts: 25
Joined: 09/25/2007 10:49 am

Postby pgolovko » 10/08/2007 1:44 pm

In ./admin/functions.php from lines 1099 to 1109 replace this:
Code: Select all
      $parent_results = mysql_query("SELECT `id`, `path` FROM `categories`");
      echo mysql_error();
      $parent_id = "";
      if(mysql_num_rows($parent_results)){
         while($parent_row = mysql_fetch_array($parent_results)){
            if($parent_row['path'] == $sub_path){
               $parent_id = $parent_row['id'];
               }
            }
         }
      $relusts = mysql_query("SELECT `title`, `description`, `keywords`, `id` FROM `categories` WHERE `path` = '$path' AND `parent` = '$parent_id' LIMIT 1");

with this:
Code: Select all
$parent_results = mysql_query("SELECT `id`, `path` FROM `categories`");
echo mysql_error();
$parent_id = "";  $possible_parents = array(); $sql_add = ""; $parent_sql = "";
if(mysql_num_rows($parent_results)){
   while($parent_row = mysql_fetch_array($parent_results)){
      if($parent_row['path'] == $sub_path){
         $parent_id = $parent_row['id'];
         $possible_parents[] = $parent_row['id'];
         }
      }
   }
if (count($possible_parents) > 0) {
   foreach ($possible_parents as $pid) {
      $parent_sql .= " `parent` = '$pid' OR ";
      }
   $length = strlen($parent_sql);
   $new = substr($parent_sql, 0, ($length - 3));
   $sql_add = " AND ($new)";
   }
$sql = "SELECT `title`, `description`, `keywords`, `id` FROM `categories` WHERE `path` = '$path' $sql_add LIMIT 1";
$relusts = mysql_query($sql);


This mod runs well on Astanda.com. Thanks Jeff :thumbright:
__________________
Best regards,
Pavel Golovko
User avatar
pgolovko
 
Posts: 494
Joined: 03/25/2006 1:23 am
Location: Somewhere on planet Earth ....

Postby newbiz » 10/08/2007 10:54 pm

:cheers: Thank You :thumbright:
newbiz
 
Posts: 25
Joined: 09/25/2007 10:49 am

another way to do it ...

Postby RonInMaine » 01/15/2008 5:44 pm

Hello,

The revised code above did not fix this issue for me. It still displayed the wrong category (just a different wrong category). See my comments in this forum post for a full description of the problem I experienced:

http://www.astanda.com/forums/viewtopic.php?p=2139

Here's what finally worked for me:

I replaced the block of code in functions.php that begins with

Code: Select all
if($r_path)
and ends with
Code: Select all
$relusts = mysql_query($sql);


with this:
Code: Select all
if($r_path)
   {
   $path_parts = split("/",$r_path);
   $selectedCategory_found = 0;
   $parentID = 0;
   $path_index = 0;
   while ($path_index < count($path_parts))
      {
      $findCategory_query = "SELECT `id` FROM `categories` WHERE path = '$path_parts[$path_index]' and `parent` = 0$parentID";
      $findCategory_result = mysql_query($findCategory_query);
      echo mysql_error();
      $CategoriesFound = mysql_num_rows($findCategory_result);
      if ($CategoriesFound == 1)
         {
         $parentID = mysql_result($findCategory_result,0,"id");
         if ($path_index == (count($path_parts)-1))
            {
            $categoryID = $parentID;
            $selectedCategory_found = 1;
            }
         }
      else
         {
         $path_index = count($path_parts);
         }
      ++$path_index;
      }
$sql = "SELECT `title`, `description`, `keywords`, `id` FROM `categories` WHERE id = $categoryID LIMIT 1";
$relusts = mysql_query($sql);


This solution is currently working for me, and it should be good for an unlimited depth of directory structure since it walks through each segment of the path from left to right to arrive at the exact category ID. If I run into any problems with this solution, I'll post here.

Thank you!
Ron.
RonInMaine
 
Posts: 10
Joined: 01/15/2008 5:31 am
Location: Maine, USA

thank you

Postby WHooBAY » 07/06/2008 4:58 am

ihave done as you told, admin.

ANd now solved my problem. thank you..

and will it support mlti editors??
WHooBAY
 
Posts: 2
Joined: 07/05/2008 6:52 am



Return to Bug Reporting

Who is online

Users browsing this forum: No registered users and 0 guests

cron