Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:07:57+00:00 2026-05-28T04:07:57+00:00

class Model_Core_NodeContents extends Zend_Db_Table_Abstract { protected $_name = ‘node_contents’; protected $_referenceMap = array( Page

  • 0
class Model_Core_NodeContents extends Zend_Db_Table_Abstract
{   
    protected $_name = 'node_contents';

    protected $_referenceMap = array(
            "Page" => array(
                    "columns" => array("node_id"),
                    "refTableClass" => "Model_Core_Node",
                    "refColumns" => array("id"),
                    "onDelete" => self::CASCADE,
                    "onUpdate" => self::RESTRICT
                    )
            );

    public function setContent($node_id,$key,$value){
        $select = $this->select()->where("node_id = ?",$node_id)->where($this->_db->quoteInto("`key` = ?",$key));
         echo $select->__toString()."<br />"; 
        $row = $this->fetchRow();
        if($row==false){
            $row = $this->createRow();           
            $row->node_id = $node_id;
            $row->key = $key;
        }
        $row->value = $value;       
        $row->save(); 
        echo $this->_db->lastInsertId();
    }

}

When I call the above code in Loop, only first item of array gets inserted in database.

foreach($data as $key => $value){
    $cnode = new Model_Core_NodeContents();                  
    $cnode->setContent($id, $key, $value);                   
}

$this->_db->lastInsertId(); returns 0 for every data item except the first.
Why? How can I insert all the rows of $data array in database by looping?

EDIT

My problem solved. $row = $this->fetchRow(); this line was incorrect. I forgot to add $select in it. Replacing that line with $this->fetchRow($select) solved my problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:07:57+00:00Added an answer on May 28, 2026 at 4:07 am

    My problem solved. $row = $this->fetchRow(); this line was incorrect. I forgot to add $select in it. Replacing that line with $this->fetchRow($select) solved my problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am trying to construct a simple update query in my model class Model_DbTable_Account extends
I have a template file: 'template.txt' like below: class Core_Model_DbTable_{table_name} extends YouNet_Db_Table { const
I need to read some data from database my controller is class Pro_ajax extends
Say I've a class (model) called Instance with Properties DatbaseHostname, AccessManagerHostname, DatabaseUsername and DatabasePassword
I have a class Model: class Model { ... boost::shared_ptr<Deck> _deck; boost::shared_ptr<CardStack> _stack[22]; };
I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,
I have a class Similar to this public class Model { public TimeSpan Time1
I have a class that has a Generic type G In my class model
I am looking for help in determining if the class model that I am
#model class Promotion(models.Model): name = models.CharField(max_length=200) start_date = models.DateTimeField() end_date = models.DateTimeField() #view def

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.