Solved

Add value to array using CodeIgniter

Posted on 2013-12-03
2
1,010 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now