Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-14-2008, 01:47 PM
Junior Member
 
Join Date: Apr 2008
Posts: 7
Default Problems

Hi,

Can someone please recreate this script and see if it produces the same results. I cannot use the same db connection for multiple queries.

Thanks

** 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'
));

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();
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-14-2008, 02:04 PM
Junior Member
 
Join Date: Apr 2008
Posts: 7
Default fixed

class searchAll{

function __construct($dbIn){
$this->db = $dbIn;
}

private function allowedImages($cid){
$db = $this->db;
$sql = "Select * from test where test_id='$cid'";
$r = $db->fetchAll($sql);
foreach ($r as $k=>$arr){
$arrN[] = $arr['name'];
}
return $arrN;
}

public function imageSearch(){
$db = $this->db;
$search = $db->fetchAll("Select * from test");

foreach ($search as $k=>$arr){
$cid = $arr['test_id'];
echo $cid;
print_r($this->allowedImages($cid));
echo "<hr>";
}
}
}

Was using query - should have used a fetchAll
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:24 AM.