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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:09:08+00:00 2026-06-10T19:09:08+00:00

I have the following function: function moveUp($row_nr){ $other_row = ($row_nr – 1); foreach ($this

  • 0

I have the following function:

function moveUp($row_nr){
        $other_row = ($row_nr - 1);
        foreach ($this -> data as &$row){
            if ($row['row_nr'] == $other_row){
                $row['row_nr']++;
            }
            else if ($row['row_nr'] == $row_nr){
                $row['row_nr']--;
            }
        }
    }

$this -> data is an array containing arrays representing rows of fields returned by an SQL query. The purpose of this function is to move the specified row up in the order by decrementing its row_nr and incrementing the row_nr of the row that was originally above it.

Unfortunately things don’t seem to be going to plan though! The row_nr doesn’t seem to update in the object. Looking at other threads I’ve seen people suggesting to use the & operator to reference the variable specifically rather than a copy of it, but as you can see in my code I’ve done that and not had a whole lot of luck with it (or perhaps I’m doing it wrong!).

I’ve also tried the lines:

$row -> row_nr++;

$row -> row_nr--;

as I’ve seen in some examples posted here but no luck there either.

Does anybody have any suggestions as to why the data array in the object doesn’t seem to be updating properly?

  • 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-10T19:09:10+00:00Added an answer on June 10, 2026 at 7:09 pm
    function moveUp($row_nr){
            $other_row = ($row_nr - 1);
            foreach ($this -> data as $key => $row){
                if ($row['row_nr'] == $other_row){
                    $this->data[$key]['row_nr']++;
                }
                else if ($row['row_nr'] == $row_nr){
                    $this->data[$key]['row_nr']--;
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code function Model(onChanged) { this.array = new Array(); this.onChanged = onChanged;
I have the following function to remove a DOM element div, $('#emDiv').on(click, ':button[data-emp-del=true]', function
i have following function: function fnGetIdentifiers(id){ $.get( 'getCultureIdentifiers.php?cultureID=' + id, function(data){ if (data.length >
I have the following function in C: uint myFunction (uint arrayLen, uint* array )
I have the following function: (function ($) { $.fn.createCommonDialog = function () { this.dialog({
i have following function where i have brands info in an array. i should
i have following function in php, how can i convert this in javascript? function
I have following function in C++ int readData ( Class1 *data) { //StartTime try{
I have following function for bookmarking a website. This function is working in Firefox,
I have the following function: jQuery(el).click(function() { var index = jQuery(this).index(), select = jQuery('select.SelectClass

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.