I need help coding a feature I'm working on to be able to add, edit, browse limitless dirs, subdirs without having to add another column onto mySQL, instead by using a path like

/home/something/something/something

in one mySQL column to browse.

I've got the basic part done of the browsing, its capable of browsing but the only problem is that it displays an undefined offset.

Could you provide assistance in fixing it or providing a totally new approach without modifying the current progress.

  $pdsnd2031 = $DB->query ("SELECT catpath FROM links_cat WHERE catid='$cid'");
   list($catpath) = $DB->getrow ($pdsnd2031);
   $xcounslash = explode("/", $catpath);
   $pn = 1;  // count the number of occurences
   while ($xcounslash[$pn] !="") {
   $pn++;
   }
  $result1 = $DB->query ("SELECT catid,cattitle,catdesc,catpath FROM links_cat WHERE (catpath LIKE '$catpath%')");
  opentable();
  echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n"
      ."  <tr>\n";
     $d = 0;
    while(list($catid,$cattitle,$catdesc,$xcatpath) = $DB->getrow ($result1)) {
    $counslash = explode("/",$xcatpath);
    $pn1 = 1;   // count the number of occurences
    while ($counslash[$pn1] !="") {
     $pn1++;
    }
      //the next line is to limit the directory to one further subdir so it doesn't display a subdir of a subdir in the subdir.
    IF ($pn1 - $pn == 1) {
      IF ($d == 2) {
         echo "  </tr>\n"
             ."  <tr>\n";
         $d = $d - 2;
      } ELSE {
         echo "    <td width='50%' valign='top'><font size='1' class='content'><center><b><a href='index.php?index=act&action=links&catid=$catid'>$cattitle</a></b></center>$catdesc</td>\n";
      $d++;
      }
    } ELSE {
        //print nothing
    }
    }

    The undefined index means you are trying to access an array index that doesn't exist. I.e. array[1000] if there are only 999 indices.
    Perhaps someone could better help you if you showed which line cause the error?

      Y'know, at a wild guess based on the variable name, I'm thinking that the loop

      $counslash = explode("/",$xcatpath);
          $pn1 = 1;   // count the number of occurences
          while ($counslash[$pn1] !="") {
           $pn1++;
          }

      Is supposed to be counting the number of slashes in $xcatpath. (It's off by one, incidentally, which is probably why the error is occurring - it will throw that Notice as soon as it runs off the end of the array).

      But if that's the case, then $pn1=substr_count($xcatpath, '/'); is all you need.

        Write a Reply...