lovis91
lovis91

Reputation: 2171

"Object of class Zend_Db_Table_Rowset could not be converted to string" in ZF

I have a problem with a query using MySQL and Zend Framework. I want to display an <option></option> with data from a database.

Using Zend, here what I've done. In my view helper:

public function bloc15()
    {
        $bdd_boutiques = new Front_Model_DbTable_Boutiques();
        $this->view->boutiques = $bdd_boutiques->fetchAll($bdd_boutiques->select()
                                                                         ->distinct()
                                                                         ->from('boutiques',
                                                                            array('ville'))
                                                          );


        return $this;

}

And in my view :

<form>
    <select id="editorsSelect" onchange="request(this);">
       <?php 
       foreach($this->boutiques as $bdd_boutiques)
       {
       ?>
           <option value="<?php echo $this->boutiques; ?>">
           <?php  echo $this->boutiques; 
           ?>
           </option>
        <?php
        }
        ?>                            
    </select> 
  </form>

I know the mistake should be obvious, but im starting with php and zend. Thanks all!

Edit: Thanks for your help, as i said, im realy bad in php. I succeded by doing that, but I'm not sure it's quite correct:

  <?php
                        foreach($this->ville as $bdd_boutiques)
                        {
                        echo $this->escape($bdd_boutiques->ville);
                        }
            ?>     

and

 $bdd_boutiques = new Front_Model_DbTable_Boutiques();
        $this->view->ville = $bdd_boutiques->fetchAll($bdd_boutiques->select()
                                                                                 ->distinct()
                                                                                 ->from('boutiques',
                                                                                    array('ville'))
                                                                  );


        return $this;

Upvotes: 0

Views: 491

Answers (1)

sshet
sshet

Reputation: 1160

You are looping through $this->boutiques and inside loop you are again using same variable $this->boutiques

   <option value="<?php echo $bdd_boutiques; ?>">
     <?php echo $bdd_boutiques; ?>
   </option>

Upvotes: 1

Related Questions