0

I have an array and I need to change the value of a column but without looping, because it duplicates the results

 $job_query = $this->db->query('SELECT * from job j , company c where j.company = c.id')->result_array();

 $companyC = $this->db->query('SELECT j.company ,c.title, c.city, c.logo , c.logo , c.contact FROM job j , company c where c.id = j.company')->result_array();

I need the column company in the first query changes to be that

$job_query['company']=$companyC[key];

but I a get the key without loop of array_map

1
  • Do you want job_query's first record's company column data ? Commented Jan 11, 2017 at 4:26

3 Answers 3

1

In codeigniter result_array() returns the all records in the form of array.So you have to use foreach loop for accessing columns.But if you want to only the first record then use row_array() as below:

$job_query = $this->db->query('SELECT * from job j , company c where j.company = c.id')->row_array();

  $companyC = $this->db->query('SELECT j.company ,c.title, c.city, c.logo , c.logo , c.contact FROM job j , company c where c.id = j.company')->row_array();

Then

$job_query['company'] = $companyC[key]; 
Sign up to request clarification or add additional context in comments.

Comments

1

yes i did that and it works the problem is that i had 2 queries but now i fixed it and don't need the first i took the value from the second one any way thanks it helped.

foreach ($job_query as $key => $value) { assigned a anew value here $new = array(); }

Comments

0

You can use array_column function for that

array_column($array, $columnname);

$array is the array you have

$columnname is the name of the key

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.