0

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 
1
  • $result is the actual result you are looking for. Just loop through it and print the result. It is not the resource. You don't have to use any kind of fetch function Commented Nov 24, 2011 at 6:31

3 Answers 3

5

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.

2
  • @root: What do you mean? You already have the data in an array. Commented Nov 24, 2011 at 6:45
  • 2
    @root: If you don't know how to print out the contents of an array you need to learn PHP before trying to work out Zend Framework. Commented Nov 24, 2011 at 6:49
0

@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}
0
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>";
  }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.