This is the code I have so far:-
$db = $this->getInvokeArg('bootstrap')->getPluginResource('db')->getDbAdapter();
$sql = "select * from users";
$result = $db->fetchAll($sql);
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Username</th>
<th>Password</th>
</tr>
";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "</tr>";
}
echo "</table>";
I am Trying this but I recieved this error:-
Warning: mysql_fetch_array() expects parameter 1 to be resource, array given in /var/www/datashow/application/controllers/IndexController.php on line 35
Zend_Db does not return mysql result objects. You don't use MySQL's functions, ever, when using the Zend_Db abstraction layer; you use Zend's functions instead. In this case, findAll
already returned the data as an array.
@root:
You already fetched the result using $result = $db->fetchAll($sql);
then why did u use while($row = mysql_fetch_array($result))
?
I would recommend you to check, what data are in your $result variable at first, using print_r($result)
. then you can use a foreach or some other efficient loop to echo the values.
foreach($result as $resultItems){ // echo value in $resultItems}
foreach($result as $row){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "</tr>";
}