Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am having alot of trouble understanding how I would process this data in the format I need it in. Please let me know if I can explain anything better.

Controller: My first step is to pass the CompanyId from the session to my model for querying, the result is an array called $data['campaigns'].

I then am trying to put each of those CampaignIds into a different array called $ids[].

Lastly I want to to run each CampaignId through a query 7 times (one for each day of the week) and assign them to an array associated with the CampaignId.

        // Assign query result to array  to be used in view
    $data['campaigns'] = $this->model_record->retrieve_campaign($CompanyId);

    foreach($data['campaigns'] as $campaign) {
        $ids[] = $campaign['CampaignId'];
    }

    foreach ($ids as $row) {
        $data['camp'][] = $row;
        for($i = 0; $i < 7; $i++) {
        $data['numbers'][] = $this->model_record->week_data($i,$row, $StartDate);}
    }

In my view, I would like to use a foreach loop to retrieve the seven results of each CampaignId and associate it with that CampaignId.

IE: CampaignId 1: 57,36,3,11,3,3,6 CampaignId 2: 3,98,193,98,21,33 etc..

I am not sure that I am constructing my controller correctly to achieve this and I have been trying to output this data in my view to no avail:

    <?php foreach ($ids as $id_item){
          echo "CampaignId " . $id_item;
          foreach ($numbers as $number_item)
          echo $number_item['MyCount'] . ",";}
?>
share|improve this question
    
You are saying that your echo statements are printing empty variables? Why are your foreach statements nested like that in the last code example? Where did the $number_items array come from? If you are just doing the last part for debugging purposes could you just use var_dump($ids) to get a better idea of the overall array structure? –  Russell Winkler Jun 30 at 21:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.