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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:31:07+00:00 2026-06-01T03:31:07+00:00

This code is only updating one row (the one that matches the first in

  • 0

This code is only updating one row (the one that matches the first in the array):

Edit: showing more code!

Here’s my view. It’s grabbing db entries based on an association (there’s one model “clients” that has a one-to-many relationship with two other models, Programs and Users).

<div class="view">
    <h2><?php echo h($program['Program']['title'])?></h1>
    <?php echo $this->Form->create('User', array('action' => 'pushing')); ?>
    <table id="pushTable">
        <tr><th colspan="5">Select the athletes you would like to push this program to:</th></tr>
        <tr>
        <?php $i=0; ?>
        <?php foreach ($clients['Players'] as $player) {?>
            <?php if ($i == 0) {?><tr><?php } ?>
            <td><?php echo $this->Form->checkbox($player['id']) . ' ' . $player['username'];?></td>
            <?php if ($i == 4) {?></tr><?php $i = 0; } else { $i++; } ?>
        <?php } ?>
        </tr>
    </table>
    <?php echo $this->Form->end(__('Push')); ?>
</div>

In my Users controller:

public function pushing() {
    if ($this->request->is('post') || $this->request->is('put')) {
        $athletes = $this->request->data['User'];
        foreach ( $athletes as $player => $flag){
            if ($flag == 0){
                unset($athletes[$player]);
            }
        }
        $this->User->updateAll(
            array('User.data' => "'foo'"),
            array('User.id' => $athletes)
        );
        $this->Session->setFlash(__('Programs were pushed!'));
        }
    }
}

$athletes is the array is collected from checked boxes, and there seem to me no problems with that… so I’m not sure why the updateAll isn’t iterating over each ID in the array…

Maybe it’s not working for a db related reason? I’m developing on MAMP… maybe the db isn’t set up for “atomic” stuff (only heard about that here today!).

I had previously tried using a foreach to loop over the id’s, then in the foreach just did this (edit: more code!)

public function pushing() {
    if ($this->request->is('post') || $this->request->is('put')) {
        foreach ($this->request->data['User'] as $player => $flag) {
            if ($flag) {
                $this->User->id = $player; // set ID to player we want to save ($player is id that was suplpied in view to checkbox
                $this->User->saveField('data', 'foo'); // then, push the data!
            }
        }
        $this->Session->setFlash(__('Programs were pushed!'));
    }
    $this->autoRender = false;
    $this->redirect(array('action' => 'index'));                    
}

But that caused weird results with redirection. No matter where I put redirection in that action, the save just wanted to do its own thing. That $this->autoRender did nothing. The controller still tried to resolve to the /pushing/ route

  • 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-06-01T03:31:09+00:00Added an answer on June 1, 2026 at 3:31 am

    Give this a shot 🙂

    In your view:

    <div class="view">
            <h2><?php echo h($program['Program']['title'])?></h1>
            <?php echo $this->Form->create('User', array('action' => 'pushing')); ?>
            <table id="pushTable">
                <tr><th colspan="5">Select the athletes you would like to push this program to:</th></tr>
                <tr>
                <?php $i=0; ?>
                <?php foreach ($clients['Players'] as $player) {?>
                    <?php if ($i == 0) {?><tr><?php } ?>
                    <td><?php echo $this->Form->input('Player.' . $player['id']. '.id', array('type' => 'checkbox', 'value' => $player['id'])) . ' ' . $player['username'];?></td>
                    <?php if ($i == 4) {?></tr><?php $i = 0; } else { $i++; } ?>
                <?php } ?>
                </tr>
            </table>
            <?php echo $this->Form->end(__('Push')); ?>
        </div>
    

    In your controller:

    public function pushing() {
        if ($this->request->is('post') || $this->request->is('put')) {
            $athletes = $this->request->data['Player'];
            $athlete_ids = array();
            foreach($athletes as $a){
                $athlete_ids[$a['id']] = $a['id'];
            }
    
            $this->User->updateAll(
                array('User.data' => "'foo'"),
                array('User.id' => $athlete_ids)
            );
            $this->Session->setFlash(__('Programs were pushed!'));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this thread some one commented that the following code should only be used
Can any one explain why the output of this code is only 'hello' and
How could I refactor this code to use only one Dir[ ] call? Dir[
Is there a pattern that I could apply to refactor this code? The only
This feels like the kind of code that only fails in-situ, but I will
How to make this css code cross browser compatible using jquery. this code only
I have this code to run a slideshow (this is only part of what
Is there anyway this code can be refactored? The only difference is the order
i made a windows service & add project installer.in which only contain this code.
Trying to figure out this pseudo code. The following is assumed.... I can only

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.