|
|||
|
Hi Folks,
I'm experiencing real issues here. class searchAll{ function __construct($dbIn,$post){ $this->db = $dbIn; $this->post = $post; } private function allowedImages($cid){ $db = $this->db; $sub_sel = $db->select() QUERY WORKS OK $te = $sql->__toString(); $tf = $db->query($te); // issue has to be db?? print "$te<br>----<br>$tf<hr>"; } public function imageSearch(){ $db = $this->db; $search = $db->select() QUERY WORKS CORRECT $search = $db->query($search); while ($row = $search->fetch()) { $cid = $row['Company_ID']; $tr = $this->allowedImages($cid); print "$cid-$tr<br>"; } } } $test = new searchAll($db,$_POST); $test->imageSearch(); I can't see why the repeated calls to allowedImages don't return a new result every time $tr is called. If you comment out the tr line it will return 8 results however if you don't it only returns one result. I think its the fact that $db is repeatedly called in the allowedImages function but can't see a workaround. Many thanks A p.s - upon further investigation the former ADODB works fine on a non persistent connection, so not quite sure what Zend is doing here?? Last edited by Ukuser26 : 04-09-2008 at 03:55 PM. |
|
|||
|
Quote:
OK - I have some sample code to resimulate this problem: ** SQL CREATE TABLE `test` ( `test_id` int(11) NOT NULL, `name` text, PRIMARY KEY (`test_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; insert into `test`(`test_id`,`name`) values (1,'test 1'),(2,'test3'),(3,'test4'),(4,'testx'); ** OOP code require_once 'Zend/Db/Adapter/Mysqli.php'; $db = new Zend_Db_Adapter_Mysqli(array( 'host' => 'localhost', 'username' => 'us', 'password' => 'pw', 'dbname' => 'db' )); // Debugging $db->getProfiler()->setEnabled(true); class searchAll{ function __construct($dbIn){ $this->db = $dbIn; } private function allowedImages($cid){ $db = $this->db; $sql = "Select * from test where test_id='$cid'"; return $db->fetchAll($sql); } public function imageSearch(){ $db = $this->db; $search = $db->query("Select * from test"); while ($row = $search->fetch()) { $cid = $row['test_id']; echo print_r($this->allowedImages($cid)); echo "<hr>"; } } } $test = new searchAll($db); // this should therefore output 4 rows of arrays $test->imageSearch(); |
![]() |
| Thread Tools | |
| Display Modes | |
|
|