php pdo oop fetch data not working -
class php
<?php class product extends db { function viewcat(){ $dbcon = new db(); $connn = $dbcon->dbcon(); try { $stmt = $connn->prepare("select * `cat`"); $resultcat = $stmt->execute(); return $resultcat; } catch (pdoexception $e) { echo 'error: ' . $e->getmessage(); } } } ?>
the view
<?php $menu = new product(); $resultmenux = $menu->viewcat(); foreach ($resultcatx $row) { print_r($row); } ?>
the error is
warning: invalid argument supplied foreach()
in class file should be, commented not fetching data
$stmt = $connn->prepare("select * `cat`"); $stmt->execute(); $resultcat = $stml->fetchall(pdo::fetch_assoc); // line missing return $resultcat;
and in view file answered shankhan
$resultmenux = $menu->viewcat(); foreach ($resultmenux $row) { print_r($row); }
Comments
Post a Comment