Jump to content

Mulitpurposing A Function


Xtremer360

Recommended Posts

I'm trying to figure out how to have it not select the title_status_id but only use it to run the get_title_statuses function to get the name of the status without having it return it in the object print.

 

$titles = $this->titles_model->get_titles(array('title_ids' =>1));

echo '<pre>';
print_r($titles);
echo '</pre>';

 

stdClass Object
(
   [title_id] => 1
   [title_name] => Undisputed Title
   [title_directory_name] => undisputed
   [title_status_id] => 1
   [title_sort_order] => 1
)

 

<?php
public function get_titles($params = array())
   {
       $this->db->select('titles.title_id');
       $this->db->select('titles.title_name');
       $this->db->select('titles.title_directory_name');
       $this->db->select('titles.title_status_id');
       $this->db->select('titles.title_sort_order');

       $this->db->from('titles');

       //checking to see if any $params are attempting to be passed
       if (count($params) > 0)
       {
           //start title specific selection
           if (isset($params['title_ids']))
           {
               //if you only have one integer.
               if (is_integer($params['title_ids']))
               {
                   $this->db->where('titles.title_id', $params['title_ids']);
                   $query = $this->db->get();
                   if ($query->num_rows() > 0)
                   {
                       $title = $query->row();
                   }
                   else
                   {
                       return false;
                   }
               }
           }
       }
   }
?>

Link to comment
https://forums.phpfreaks.com/topic/270571-mulitpurposing-a-function/
Share on other sites

Basically the get_titles function will handle all kinds of situations but I'm going to try and do this one situation at a time. When the function is called with just one id (title_id) I want it to return data just about that title. When it gets the status_id I want it to take that value to the get_title_statuses function so it can get the name of that status.

 

So the returned object should be this for a single row.

 

stdClass Object
(
   [title_id] => 1
   [title_name] => Undisputed Title
   [title_directory_name] => undisputed
   [title_status_name] => Active
   [title_sort_order] => 1
)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.