Solved

Add value to array using CodeIgniter

Posted on 2013-12-03
2
1,115 Views
Last Modified: 2013-12-03
I am using CodeIgniter to generate some query results, and then in a second step using a foreach loop to run a method using values from the query result. What I would like to do now is to somehow combine the new variable with the original query. Here is the code so far:

$qryOriginal = $this->db->query("SELECT 1 as BAND, 
  tblappeals.Scenario, 
  tblappeals.Year, 
  tblappeals.var1, 
  tblappeals.var2 
  FROM tblappeals 
  WHERE tblappeals.Property = $pn ");

foreach ($qryOriginal->result() as $row)
{
$var3 = $this->getPhaseIn($calcyear, $row->var1, $row->var2);
    echo $var3; //HOW CAN I ADD THIS $var3 VALUE TO qryOriginal ???  
}

Open in new window

There must be an easy way to add this new value to the original query. I just don't know how to do it. I was thinking to use array_push(), but that doesn't seem to be the right function. Any ideas?
0
Comment
Question by:DanielAttard
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 39694538
$qryOriginal is a query, not a result set. Perhaps you want to do this?

$qryOriginal = $this->db->query("SELECT 1 as BAND, 
  tblappeals.Scenario, 
  tblappeals.Year, 
  tblappeals.var1, 
  tblappeals.var2 
  FROM tblappeals 
  WHERE tblappeals.Property = $pn ");

$results = $qryOriginal->result();
foreach ($results as $key=>$row)
{
  $results[$key]->var3 = $this->getPhaseIn($calcyear, $row->var1, $row->var2);
}

Open in new window

0
 

Author Closing Comment

by:DanielAttard
ID: 39694553
Thanks Terry, that was awesome.  You nailed it first shot.  Made my night.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to count occurrences of each item in an array.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question