Welcome Guest, Not a member yet? Register   Sign In
need to pass email field value into variable
#1

[eluser]Brad K Morse[/eluser]
model function: gets email of $venue_id = id

Code:
function getVenueChairEmail($venue_id) {
  $q = $this->db->select('email')->where('id',$venue_id)->get('venues');
}

Then I want to pass the email into the variable $to, like I am trying to do below

Code:
$to = $this->data_model->getVenueChairEmail($venue_id);

It is not passing anything into $to, tested by printing it out, empty.

I imagine its not as easy as that, any help is appreciated.
#2

[eluser]skunkbad[/eluser]
Have you tested the raw query on the database to see if it returns anything? According to your code, it looks like your query is:

SELECT email from venues WHERE id = $venue_id;

If you plug in a venue id and it doesn't work, then there's your problem.

If it does work, then you should look at the value of $venue_id before you try to pass it to the model.
#3

[eluser]Greg Aker[/eluser]
You need to return from the model function.

try:

model:
Code:
public function get_venue_chair_email($venue_id)
{
    $qry = $this->db->select('email')
                    ->where('id', $venue_id)
                    ->get('venues');
    
    // We get a result?
    if ($qry->num_rows() === 0)
    {
        return FALSE;
    }
    
    return $qry->row('email');
}

Controller:

Code:
$to = $this->data_model->get_venue_chair_email($venue_id)

if ($to === FALSE)
{
    // to failed, maybe time for an error.
}

-greg
#4

[eluser]Brad K Morse[/eluser]
Thank you Greg! That did the trick, you're 2 for 2!
#5

[eluser]Greg Aker[/eluser]
If you don't have it. get xdebug running on your dev environment. using var_dump with that installed, and you'll see all sorts of pretty things about your data. Smile




Theme © iAndrew 2016 - Forum software by © MyBB