Question

I'm trying to pull two columns as an array using a technique that has worked for me in other places so far. But it is only returning the first column's values with empty values for the second column.

Here's my controller

function status()
{
  $this -> load -> model('model');
  $data['query'] = $this -> model -> checkWebStatus('database');

  if ($this -> uri -> segment(3) == '')
  {
    $this -> template -> set_content('status_view', $data);
    $this -> template -> build();
  }
}

The model looks like this:

function checkWebStatus($database)
{
  $this -> external_db = $this -> load -> database($database, TRUE);
  $query = $this -> external_db -> select('name_code, active_franchise');
  $query = $this -> external_db -> order_by('active_franchise DESC, name_code ASC');
  $query = $this -> external_db -> get('database_table');

  return($query -> result());
}

And my view looks like this...

foreach ($query as $result)
{
  echo $result -> name_code;
  print ' ';
  echo (isset($result -> active_franchise)) ? $result -> active_franchise : 'var unset';
  print '<br />';
}

I end up with an array of name_code(s) and accompanying "var unset" messages. Any advice? As I said this system has worked fine before with different names for the columns, the only difference being this database is explicitly set in the model whereas the area it appears to work on is on the default "db" through Codeigniter.

I appreciate your time reading this, thank you.

---EDIT---

Crap I suck, can't believe I missed the typo. BUT. It did not solve the issue. Now instead of showing "var unset" it simply lists no value at all. It should return either a 1 or 0.

---EDIT 2---

var_dump($result) returns....

object(stdClass)#24 (2) { ["name_code"]=> string(6) "GECAOC" ["active_franchise"]=> string(1) "" } GECAOC 
object(stdClass)#25 (2) { ["name_code"]=> string(6) "GEPACT" ["active_franchise"]=> string(1) "" } GEPACT 
object(stdClass)#26 (2) { ["name_code"]=> string(6) "GEWAES" ["active_franchise"]=> string(1) "" } GEWAES 

No correct solution

OTHER TIPS

  echo (isset($result -> active_frachise)) ? $result -> active_franchise : 'var unset';
  print '<br />';

Change to

  echo (isset($result -> active_franchise)) ? $result -> active_franchise : 'var unset';
  print '<br />';

It is never even getting to the point where you can echo active franchise because the isset returns false

Got it dead right @Chitowns24 I edited the table's column from bit as the type to tinyint(1) and set it to not null (compared to a VERY similar set to code used in another area that worked and saw that difference in that field) and now it pulls down the value as intended.

Lucky me the code was good I just didn't arrange the table when it was setup!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top