last day (14 days later) » 

1:16 PM
0
A: create an index of array inside foreach loop ci

Amit Gaudjust use this single query and let me know what is output this is giving $this->db->select("generic_table.name,main_data.path"); $this->db->from('generic_table'); $this->db->where("generic_table.id",$id); $this->db->join("main_data","main_data.f_key = generic_table.id"); $query = $this->db->...

 
Array ( [id] => 14 [path] => Array ( [0] => Array ( [id] => 16 [path] => almond.jpg ) ) )
the join is somewhere incorrect it is not comparing the id's the id's are 13,14 and it is returning 14,16
 
how the tables are related to each other?
now you have to php coding to show proper path in view file
 
alright i got it working it is returning correct array like Array ( [0] => Array ( [name] => Almonds [path] => almond.jpg ) ) if i am using $this->Menu->test_maindata("14");
only thing remains how do i do the same inside a loop and prevent overriding?
 
sorry I didn't understand ?
 
but it is replacing data e.g when the loop runs first id is 13 it gets the data and puts it in the array and when the second iteration runs when the id is 14 it overrides the previous data and returns the data of only the last iteration that is 14 which is actually happening this is the array it is returning Array ( [id] => 14 [path] => Array ( [0] => Array ( [name] => Almonds [path] => almond.jpg ) ) ) how can i make it store both 13 and 14 id's array?
SORRY ignore that comment let me write a new detailed none
one***
i have id 13,14,on every iteration it overrides the previous values, when the loop runs first id is 13 it gets the data and puts it in the array and when the second iteration runs when the id is 14 it overrides the previous data and returns the data of only the last iteration that is 14 which is actually happening this is the array it is returning Array ( [id] => 14 [path] => Array ( [0] => Array ( [name] => Almonds [path] => almond.jpg ) ) ) how can i make it store both 13 and 14 id's array?
 
1:25 PM
then this sould be like $arrOfIds = $data['child1'];
          foreach($arrOfIds as $row) {
             $data['child3'][]=array
            (
                "id" => $row["id"],
                "path" => $this->Menu->test_maindata($row["id"])
            );
          }
 
o perfect man thanks...:)
can you put this answer on the post so i can mark it?
just one last thing
in my view how do i access it? like here is my code
<?php foreach ($child3 as $c): ?>

<div class="col-xs-12 col-sm-6 col-md-4">
<img src="<?=base_url()?>uploads/<?=$c->path?>" class="img-responsive">
<h3><?php $c->name ?></h3>
</div>


<?php endforeach ?>
 

last day (14 days later) »