function chado_get_table_max_rank

2.x tripal_core.chado_general.api.inc chado_get_table_max_rank($tablename, $where_options)
3.x tripal_chado.query.api.inc chado_get_table_max_rank($tablename, $where_options)

Get max rank for a given set of criteria This function was developed with the many property tables in chado in mind but will work for any table with a rank

@params tablename: the name of the chado table you want to select the max rank from this table must contain a rank column of type integer @params where_options: array( <column_name> => array( 'type' => <type of column: INT/STRING>, 'value' => <the value you want to filter on>, 'exact' => <if TRUE use =; if FALSE use ~>, ) ) where options should include the id and type for that table to correctly group a set of records together where the only difference are the value and rank

Return value

the maximum rank

Related topics

4 calls to chado_get_table_max_rank()
chado_update_node_form_properties in tripal_core/api/tripal_core.chado_nodes.properties.api.inc
This function is used in hook_insert or hook_update and handles inserting of any new properties
chado_update_node_form_relationships in tripal_core/api/tripal_core.chado_nodes.relationships.api.inc
This function is used in hook_insert or hook_update and handles inserting of relationships between the current nodetype and other memebers of the same nodetype
get_max_chado_rank in tripal_core/api/tripal_core.DEPRECATED.api.inc
tripal_get_max_chado_rank in tripal_core/api/tripal_core.DEPRECATED.api.inc
2 string references to 'chado_get_table_max_rank'

File

tripal_core/api/tripal_core.chado_general.api.inc, line 158
Provides an application programming interface (API) to manage data withing the Chado database.

Code

function chado_get_table_max_rank($tablename, $where_options) {

  $where_clauses = array();
  $where_args = array();

  //generate the where clause from supplied options
  // the key is the column name
  $i = 0;
  $sql = "
    SELECT max(rank) as max_rank, count(rank) as count
    FROM {" . $tablename . "}
    WHERE
  ";
  foreach ($where_options as $key => $value) {
    $where_clauses[] = "$key = :$key";
    $where_args[":$key"] = $value;
  }
  $sql .= implode($where_clauses, ' AND ');

  $result = chado_query($sql, $where_args)->fetchObject();
  if ($result->count > 0) {
    return $result->max_rank;
  }
  else {
    return -1;
  }

}