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 6197363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:48:25+00:00 2026-05-24T03:48:25+00:00

In my cake app I have a model called faqs, controller called faqs_controller &

  • 0

In my cake app I have a model called faqs, controller called faqs_controller & view called faqsindex.php.

I’m making a CMS so users can change the FAQs. The db table ‘faqs’ has 5 columns id, category, question, answer and number. “Number” is the order in which the FAQ’s will appear.

The loop that lists all of the FAQs looks more or less like this:

<?php
foreach ($faqs as $faq):
<tr>
<td><?php echo $faq['Faq']['category']; ?></td>
<td><?php echo $faq['Faq']['number']; ?></td>
<td><?php echo $faq['Faq']['question']; ?></td>
<td><?php echo $faq['Faq']['answer']; ?></td>
</tr>
<?php endforeach; ?>

I want to make it so that the user can change the “number” cell from this screen, instead of going into a separate edit screen for each row and changing the number there.

You know, like how netflix’s queue works, where the user can reorder it from the list, you don’t have to click on the movie you want to see to change its order in your queue.

EDIT I set up edit in faqs_controller.php like this:

    function edit() {
       if(!empty($this->data)) {
          $this->Faq->saveAll($this->data['Faq']);
       }
       else {
          $this->data['Faq'] = Set::combine($this->Faq->find('all'), '{n}.Faq.id', '{n}.Faq');
       }
}

and in the index view I made a foreach that looks like this:

echo $form->create('Faq', array('action'=>'edit'));
foreach($this->viewVars['faqs'] as $key => $value) {
    echo 'id:'.$value['Faq']['id'];
    echo '<br/>question:'.$value['Faq']['question']; 
    echo $form->input('Faq.'.$key.'.number');
}

In this case the foreach goes round 8 times because there are 8 rows. If I submit them, I create 8 new rows & can’t update existing rows.

-EDIT-

I changed the form echo here:

echo $form->input(‘Faq.’.$key.’.question’,array(‘value’=>$value[‘Faq’][‘question’]));

to prepopulate the form. What I can’t figure out is how to update the proper row. If I submit the form I get 8 mysql queries like this:

INSERT INTO faqs (question) VALUES (‘THE NEW QUESTION I JUST ADDED?’) when I don’t want an insert but an update.

  • 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-24T03:48:27+00:00Added an answer on May 24, 2026 at 3:48 am

    Put each faq id inside your form?

    echo $form->create('Faq', array('action'=>'edit'));
    foreach($this->viewVars['faqs'] as $key => $value) {
        echo 'id:'.$value['Faq']['id'];
        echo '<br/>question:'.$value['Faq']['question']; 
        echo $form->hidden('Faq.'.$key.'.id', array('value' => $value['Faq']['id']));
        echo $form->input('Faq.'.$key.'.number');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Profile model/controller in my cake app as well as an index.ctp
I´m starting to developing with cake php. I have designed a DB model and
I have to use MS SQL Server 2008 to store data of PHP CAKE
I am a Cake PHP novice. I want to edit the table Issue. This
How can I get the built-in date formatting working in my Cake app? Maybe
I want to integrate Wordpress blog in my Cake PHP Site. When I logged
I'm developing an app with CakePHP and in my app I have an admin
I have a CakePHP app which I have been developing on a remote server.
I'm struggling to implement ACL in CakePHP. After reading the documentation in the cake
I've got to write few words about C#, generally piece of cake? No! I've

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.