1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- function get_max_chado_rank ($tablename, $where_options) {
- $where= array();
-
-
- foreach ($where_options as $key => $val_array) {
- if (preg_match('/INT/', $val_array['type'])) {
- $where[] = $key."=".$val_array['value'];
- } else {
- if ($val_array['exact']) { $operator='='; }
- else { $operator='~'; }
- $where[] = $key.$operator."'".$val_array['value']."'";
- }
- }
-
- $previous_db = tripal_db_set_active('chado');
- $result = db_fetch_object(db_query(
- "SELECT max(rank) as max_rank, count(rank) as count FROM %s WHERE %s",
- $tablename,
- implode(' AND ',$where)
- ));
- tripal_db_set_active($previous_db);
-
- if ($result->count > 0) {
- return $result->max_rank;
- } else {
- return -1;
- }
- }
|