I have two concerns with the castracker_options_select function. First, there is no table prefixing possible (easy fix, just make it {%s}). Second, it looks to me like it selects all from whatever table gets passed in by the $table variable. One of the calls to this function gets the list of projects that a case can belong to. It passes term_data in as the table. That means that in order to build a select box with all the projects in it, the entire term_data table is being selected and iterated over. Or am I misreading this?

/**
 * Function to get the option values for form select box
 */

function casetracker_options_select($table, $value_field, $disp_field) {
  $result = db_query("SELECT * FROM %s", $table);
  $options = Array();
  while ($row = db_fetch_array($result)) {
    $options[$row[$value_field]] = $row[$disp_field];
  }
  if ($table == 'users') {
    unset($options[0]);
  }
  return $options;
}

Comments

sanjeev gupta’s picture

No Robert you are correct.I have updated the function castracker_options_select.Now when there is is a fetching of data from the {term_data} data I have imposed the condition that the term data should belong to a particular category

   **
 * Function to get the option values for select box
 */

function casetracker_options_select($table, $value_field, $disp_field, $filter = null) {
  if (!$filter) { 
    $result = db_query("SELECT * FROM {%s}", $table);
  }
  else if ($filter == 'term_type') {
    $result = db_query("SELECT * FROM {%s} WHERE vid = %d", $table, _casetracker_get_vid()); 
  }  
  $options = Array();
  while ($row = db_fetch_array($result)) {
    $options[$row[$value_field]] = $row[$disp_field];
  }
  if ($table == 'users') {
    unset($options[0]);
  }
  return $options;
}
   

It is basically a modular function and has its limitation and I intend to use this function for this specific module.

sanjeev gupta’s picture

Status: Active » Fixed

No Robert you are correct.I have updated the function castracker_options_select.Now when there is is a fetching of data from the {term_data} data I have imposed the condition that the term data should belong to a particular category

   **
 * Function to get the option values for select box
 */

function casetracker_options_select($table, $value_field, $disp_field, $filter = null) {
  if (!$filter) { 
    $result = db_query("SELECT * FROM {%s}", $table);
  }
  else if ($filter == 'term_type') {
    $result = db_query("SELECT * FROM {%s} WHERE vid = %d", $table, _casetracker_get_vid()); 
  }  
  $options = Array();
  while ($row = db_fetch_array($result)) {
    $options[$row[$value_field]] = $row[$disp_field];
  }
  if ($table == 'users') {
    unset($options[0]);
  }
  return $options;
}
   

It is basically a modular function and has its limitation and I intend to use this function for this specific module.

Anonymous’s picture

Status: Fixed » Closed (fixed)