ZEND Query Syntax probleM

When I run the following piece of code My FOREACH statement will not work.  What am I doing wrong here?
		$sel = $db->query("SELECT region_id FROM regions WHERE manager_id ='$user_id'");			 
		//$rid = $sel->fetchAll();
		$rid_view = $sel->fetchColumn(0);
		echo 'Region ID:: ';
		echo $rid_view;

		echo '<br />';		
//  END GRAB REGION ID ASSOCIATED WITH THIS MANAGER ID  //
		
		
//  START GRAB PROPERTY ID FROM PROPERTIES WITH THE REGION ID  //
		$selb = "SELECT property_id FROM properties WHERE region_id = '$rid_view'";	
		$stmt = $db->query($selb);
		$rows = $stmt->fetchAll(); 
		foreach($rows as $row) {
		echo 'PROPERTY ID: ';
		echo $row['property_id'];	
		echo '<br />';
		}

Open in new window

LVL 8
rgranlundAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
foreach() is looking for $rows.  Where is $rows?  Can you please use var_dump($rows) to show us the content of the $rows variable?
0
rgranlundAuthor Commented:
Its on line 14 right above the foreach line.
0
Ray PaseurCommented:
Good.  What is contained in that variable?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

rgranlundAuthor Commented:
array(0) { }

Hmmm.  Interesting.
0
Ray PaseurCommented:
Looks like you might want to use var_dump($stmt) next ;-)

If we follow this chain back up through the variables I am sure we can find the culprit!
0
rgranlundAuthor Commented:
It seems to be doing everything correct until the end and I'm not really sure.  Some of the last lines leave the Query empty.

object(Zend_Db_Statement_Pdo)#74 (9) {
  ["_fetchMode:protected"]=>
  int(2)
  ["_stmt:protected"]=>
  object(PDOStatement)#75 (1) {
    ["queryString"]=>
    string(57) "SELECT property_id FROM properties WHERE region_id = '12'"
  }
  ["_adapter:protected"]=>
  object(Zend_Db_Adapter_Pdo_Mysql)#20 (12) {
    ["_pdoType:protected"]=>
    string(5) "mysql"
    ["_numericDataTypes:protected"]=>
    array(16) {
      [0]=>
      int(0)
      [1]=>
      int(1)
      [2]=>
      int(2)
      ["INT"]=>
      int(0)
      ["INTEGER"]=>
      int(0)
      ["MEDIUMINT"]=>
      int(0)
      ["SMALLINT"]=>
      int(0)
      ["TINYINT"]=>
      int(0)
      ["BIGINT"]=>
      int(1)
      ["SERIAL"]=>
      int(1)
      ["DEC"]=>
      int(2)
      ["DECIMAL"]=>
      int(2)
      ["DOUBLE"]=>
      int(2)
      ["DOUBLE PRECISION"]=>
      int(2)
      ["FIXED"]=>
      int(2)
      ["FLOAT"]=>
      int(2)
    }
    ["_defaultStmtClass:protected"]=>
    string(21) "Zend_Db_Statement_Pdo"
    ["_config:protected"]=>
    array(8) {
      ["host"]=>
      string(9) "*********"
      ["username"]=>
      string(13) "********"
      ["password"]=>
      string(4) "******"
      ["dbname"]=>
      string(12) "*******"
      ["charset"]=>
      string(4) "utf8"
      ["driver_options"]=>
      array(1) {
        [1002]=>
        string(16) "SET NAMES 'utf8'"
      }
      ["persistent"]=>
      bool(false)
      ["options"]=>
      array(3) {
        ["caseFolding"]=>
        int(0)
        ["autoQuoteIdentifiers"]=>
        bool(true)
        ["fetchMode"]=>
        int(2)
      }
    }
    ["_fetchMode:protected"]=>
    int(2)
    ["_profiler:protected"]=>
    object(Zend_Db_Profiler)#21 (4) {
      ["_queryProfiles:protected"]=>
      array(3) {
        [0]=>
        object(Zend_Db_Profiler_Query)#59 (5) {
          ["_query:protected"]=>
          string(7) "connect"
          ["_queryType:protected"]=>
          int(1)
          ["_startedMicrotime:protected"]=>
          float(1382021595.87)
          ["_endedMicrotime:protected"]=>
          float(1382021595.87)
          ["_boundParams:protected"]=>
          array(0) {
          }
        }
        [1]=>
        object(Zend_Db_Profiler_Query)#73 (5) {
          ["_query:protected"]=>
          string(53) "SELECT region_id FROM regions WHERE manager_id ='149'"
          ["_queryType:protected"]=>
          int(32)
          ["_startedMicrotime:protected"]=>
          float(1382021595.87)
          ["_endedMicrotime:protected"]=>
          float(1382021595.87)
          ["_boundParams:protected"]=>
          array(0) {
          }
        }
        [2]=>
        object(Zend_Db_Profiler_Query)#76 (5) {
          ["_query:protected"]=>
          string(57) "SELECT property_id FROM properties WHERE region_id = '12'"
          ["_queryType:protected"]=>
          int(32)
          ["_startedMicrotime:protected"]=>
          float(1382021595.87)
          ["_endedMicrotime:protected"]=>
          float(1382021595.87)
          ["_boundParams:protected"]=>
          array(0) {
          }
        }
      }
      ["_enabled:protected"]=>
      bool(true)
      ["_filterElapsedSecs:protected"]=>
      NULL
      ["_filterTypes:protected"]=>
      NULL
    }
    ["_defaultProfilerClass:protected"]=>
    string(16) "Zend_Db_Profiler"
    ["_connection:protected"]=>
    object(PDO)#66 (0) {
    }
    ["_caseFolding:protected"]=>
    int(0)
    ["_autoQuoteIdentifiers:protected"]=>
    bool(true)
    ["_allowSerialization:protected"]=>
    bool(true)
    ["_autoReconnectOnUnserialize:protected"]=>
    bool(false)
  }
  ["_attribute:protected"]=>
  array(0) {
  }
  ["_bindColumn:protected"]=>
  array(0) {
  }
  ["_bindParam:protected"]=>
  array(0) {
  }
  ["_sqlSplit:protected"]=>
  array(1) {
    [0]=>
    string(53) "SELECT property_id FROM properties WHERE region_id = "
  }
  ["_sqlParam:protected"]=>
  array(1) {
    [0]=>
    string(53) "SELECT property_id FROM properties WHERE region_id = "
  }
  ["_queryId:protected"]=>
  int(2)
}

array(0) {
}
PROPERTY ID: 

Open in new window

0
Ray PaseurCommented:
How many rows do you expect to get back from the $selb query?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
Well, I tinkered and tinkered and finally came up with this:
		$rid_new = $rid_view;
		$selb = "SELECT property_id FROM properties WHERE region_id ='$rid_new'";	
		$stmt = $this->db->fetchAssoc($selb);
		echo '<pre>';
		var_dump($stmt); 
			foreach($stmt as $row) {
			echo $row['property_id'];	
		echo '<br />';
			}

Open in new window

However, I would have come up with this solution hours ago if I had made sure that there were actually properties assigned to that region.

It was your last note that set me straight.

Thank you.  I feel dumb now.
0
rgranlundAuthor Commented:
I am starting a new question but it is an extension of this one:
0
Ray PaseurCommented:
I wouldn't feel dumb about this if I were you -- it's part of learning the process, and next time you'll get good results faster because of what you're learning here!

Thanks for the points and best of luck with the project, ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.