-2

Please I need your help ! I am creating an application that manages the articles for each page with zend framework 1. I want to display for each page its articles.

public function getPagearticle(){
    $db = Zend_Db_Table::getDefaultAdapter();
    $select = new Zend_Db_Select($db);
    $select = $db->select()
          ->from(array('a' => 'articles'), array('page_id', 'Nom_article'))
          ->join(array('p' => 'pages'), 'p.id = a.page_id',array('p.nom'));
    $resultRows = $this->fetchAll($select);


    }

but I got this error :SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1, query was: SELECT articles.* FROM articles WHERE ( Thank you for helping me

  • 1
    Without knowing Zend it seems odd that this query builder would build this query (no columns, joins and an odd empty where). Are you sure this is the correct piece of code? – h2ooooooo May 22 '14 at 11:14
  • Does the error call stack get you back to this method? I certainly doubt! Please check again and tell us what you get. – php-dev May 22 '14 at 13:21
  • Your code will produce this query: `SELECT a.page_id, a.Nom_article, p.nom FROM articles AS a INNER JOIN pages AS p ON p.id = a.page_id`, and no the one you want. You need to be more precise in your question. – Volvox May 22 '14 at 15:33

2 Answers2

0

the application displays the names of the pages for each page can be edited. Clicking on "edit" it displays its articles which can edit, delete that is all the code of Articlemodel

class Application_Model_DbTable_Articles extends Zend_Db_Table_Abstract {

protected $_name = 'articles';

public function __construct(){
    parent::__construct();
}


 public function getPagearticle(){
    $db = Zend_Db_Table::getDefaultAdapter();
    $select = new Zend_Db_Select($db);
    $select = $db->select()
          ->from(array('a' => 'articles'), array('page_id', 'Nom_article'))
          ->join(array('p' => 'pages'), 'p.id = a.page_id',array('p.nom'));
    $resultRows = $this->fetchAll($select);


    }



     public function getArticle($id)
{
    $id = (int)$id;
    $row = $this->fetchRow('id = ' . $id);

    if (!$row) {
        throw new Exception("Could not find row $id");
    }
    return $row->toArray();
}





public function addArticle($Nom_article, $description,$Img,$date, $Contenue,$is_show)
{
    $data = array(
        'Nom_article' => $Nom_article,
        'description' => $description,
        'Img' => $Img,
        'date'=>$date,
        'Contenue' => $Contenue,
        'is_show'=> $is_show

    );
    $this->insert($data);
}

public function updateArticle($id,$Nom_article, $description,$Img,$date, $Contenue,$is_show)
{
    $data = array(
       'Nom_article' => $Nom_article,
        'description' => $description,
        'Img' => $Img,
        'date'=>$date,
        'Contenue' => $Contenue,
        'is_show'=> $is_show
    );
    $this->update($data, 'id = '. (int)$id);
}

public function deleteArticle($id)
{
    $this->delete('id =' . (int)$id);
}

}

-1

Actually I never used your approach in that situation.

What i use from a generic ::getDefaultAdapter() is just a plain text query like

"SELECT page_id, nom_article FROM articles join ..."

And I build the select on a table object

http://framework.zend.com/manual/1.10/en/zend.db.table.html

Try to use

$resultRows = $db->fetchAll($select);

instead of your $this->fetchAll($select);

Gounemond
  • 353
  • 1
  • 9