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

  • Home
  • SEARCH
  • 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 8992021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:51:35+00:00 2026-06-15T22:51:35+00:00

I have the following PHP code: $alignments = new StdClass(); if ($query->num_rows > 0)

  • 0

I have the following PHP code:

$alignments = new StdClass();

        if ($query->num_rows > 0)
        {
            foreach($query->result() as $row){
                $alignments->{$row->table_id} = new StdClass();

                $alignments->{$row->table_id}->table_id = isset($row->table_id)?$row->table_id:NULL;
                $alignments->{$row->table_id}->title = isset($row->title)?$row->title:NULL;
                $alignments->{$row->table_id}->url = isset($row->url)?$row->url:NULL;
                $alignments->{$row->table_id}->state_id = isset($row->state_id)?$row->state_id:NULL;
                $alignments->{$row->table_id}->cross_discipline_alignment = isset($row->cross_discipline_alignment)?$row->cross_discipline_alignment:NULL;
                $alignments->{$row->table_id}->common_core = isset($row->common_core)?$row->common_core:NULL;
                $alignments->{$row->table_id}->grade_level = isset($row->grade_level)?$row->grade_level:NULL;
                $alignments->{$row->table_id}->indicators = new StdClass();
                $alignments->{$row->table_id}->indicators->{$row->indicator_id} = new StdClass();
                $alignments->{$row->table_id}->indicators->{$row->indicator_id}->indicator_id = isset($row->indicator_id)?$row->indicator_id:NULL;
                $alignments->{$row->table_id}->indicators->{$row->indicator_id}->indicator = isset($row->indicator)?$row->indicator:NULL;
                $alignments->{$row->table_id}->indicators->{$row->indicator_id}->key = isset($row->key)?$row->key:NULL;
                $alignments->{$row->table_id}->indicators->{$row->indicator_id}->extra_data = isset($row->extra_data)?$row->extra_data:NULL;
                $alignments->{$row->table_id}->indicators->{$row->indicator_id}->uri_k5 = isset($row->uri_k5)?$row->uri_k5:NULL;
                $alignments->{$row->table_id}->indicators->{$row->indicator_id}->uri_612 = isset($row->uri_612)?$row->uri_612:NULL;
            }

            return $alignments;
        }

The problem is that in the foreach loop if there are multiple items with the same $row->table_id then the last one in the loop is set (ignoring all others). I have tried the !isset($alignments->{row->table_id}) and it is still overriding. I am trying to say that if the variable of $alignments->{$row->table_id} exists, use it, if not, set it to a new StdClass()

  • 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-15T22:51:36+00:00Added an answer on June 15, 2026 at 10:51 pm

    Maybe you need to wrap your initialization like this:

    if (!property_exists($alignment, $row->table_id)) {
      $alignments->{$row->table_id} = new StdClass();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following PHP code $val=<div id=user.$row['cid']. userid=.$row['cid']. class=innertxt><img src=images/images.jpg width=50 height=50><strong>.$uname.</strong><ul> <li>Email: .$row['cemail'].</li>
I have the following PHP code: $data=mysql_query(SELECT * FROM notes WHERE rootNoteId='$noteId'); $mainArray; while($result
I have the following PHP code which runs a MySQL query and returns the
I have the following PHP example code: $client = new SoapClient("http://example.com/example.wsdl"); $h = Array();
I have the following PHP code: foreach (...) { try { $Object = MyDataMapper::getById(123);
I have the following web php code: while ($row = mysql_fetch_array($results, MYSQL_NUM)) { printf(<p>ID:
I have following code (php), it will match img-src and replace with new url
I have the following PHP code: $required_fields = array ('menu_name','visible','position'); foreach($required_fields as $fieldname) {
I have the following php code that gives me an unexpected result: $foo =
I have the following php code that runs after validation: try { if (isset($filtered)

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.