Fork me on GitHub

PNINIT question for new example  Bottom

  • when setting indexes.

    Code

    // Define columns with index
        $idxflds = $Examplecolumn['number'];


    If I have multiple indexes I need to define how do I do it?
  • Can you just define them in an array???



    -SUNADMN
  • having a hard time wrapping my head around this concept. I know that I cant store the information into my index schema array with the table as the key now that I think of it. Because it would just rewrite the information each iteration of the key. Anyone have a suggestion? I know I could always just put it down as individual entries but I was just trying to do something that was easier to read with less code.

    Code

    $idxschema[$helpdeskticketstable]   = ticket_statusid => '$helpdeskticketscolumn[ticket_statusid]';
        $idxschema[$helpdeskticketstable]   = ticket_typeid =>  '$helpdeskticketscolumn[ticket_typeid]';
        $idxschema[$helpdeskticketstable]   = ticket_priorityid =>  '$helpdeskticketscolumn[ticket_priorityid]';
        $idxschema[$helpdeskticketstable]   = ticket_openedby =>    '$helpdeskticketscolumn[ticket_openedby]';
        $idxschema[$helpdeskticketstable]   = ticket_assignedto =>  '$helpdeskticketscolumn[ticket_assignedto]';

        $idxschema[$helpdeskhistoriestable] = ticket_id =>  '$helpdeskhistoriescolumn[ticket_id]';
        $idxschema[$helpdeskhistoriestable] = history_updatedby =>  '$helpdeskhistoriescolumn[history_updatedby]';

        ////////////////////////////////////////////////////////////////////////////////////////////
        foreach ($idxschema as $table => $idxflds => $idxname) {
        // Define the name of the index
        // Define columns with index
            $sqlarray = $dict->CreateIndexSQL($idxname, $table, $idxflds);
            // Check for an error with the database code, and if so set an
            // appropriate error message and return
            if ($dict->ExecuteSQLArray($sqlarray) != 2) {
                pnSessionSetVar('errormsg', _HELPDESKCREATEINDEXFAILED);
                return false;
            }

        }
  • I wrote some code to do the trick.
    It could probably use some optimizing, but it works nicely for me.
    Any questions, PM me.

    Code

    // define the various index variables $idxname, $table, $idxflds
    // using a suffix corresponding to the array key value

    // variable group 0
    $idxname0 = "name0";
    $table0 = "tab0";
    $idxflds0 = "fld0";

    // variable group 1
    $idxname1 = "name1";
    $table1 = "tab1";
    $idxflds1 = "fld1";

    // variable group 2
    $idxname2 = "name2";
    $table2 = "tab2";
    $idxflds2 = "fld2";

    // Loop the variables as required
    // Remember to add to the array list as you add more variable groups
     
    $arr = array( "0" => array("$idxname0", "$table0", "$idxflds0"),
                  "1" => array("$idxname1", "$table1", "$idxflds1"),
                  "2" => array("$idxname2", "$table2", "$idxflds2")
                         );
      $flow = 0;
      foreach($arr as $flow => $array){
      // ... and creating the index
      $sqlarray = $dict->CreateIndexSQL($arr[$flow][0], $arr[$flow][1], $arr[$flow][2]);
      $flow++;
      }
  • sweet thanks pnfreek thats exactly what I had in mind.

This list is based on users active over the last 60 minutes.