Welcome Guest, Not a member yet? Register   Sign In
small problem [Solved]
#1

[eluser]psolms[/eluser]
so, heres what im looking at. in my database, for the purposes of this problem, i have 4 tables. cities, stores, collections and hascollections.

cities are just a name and an id
stores is the usual stores info (linked to a city)
collections are which collections are available and also the icon for each
hascollections is the connector. (a record is just storeId + collectionId)

cities -> stores <> hascollections <> collections

- = 1
>(<) = many

pretty simple so far, right?

here is the issue: the user selects a city, then all the stores in a city are listed. this works just fine right now. i need to add the collection icons for each store.

here is the code in question (that works right now):
Controller: map.php
Code:
function city_select()
  {
    $cityId = $_POST['city'];
    $regionId = $_POST['regionId'];
    $store = $this->store->lookup_stores($cityId);
    $data['img_path'] = base_url().'system/application/images/';
    $data['city'] = $this->city->lookup_cities($regionId);
    $data['region'] = $this->region->lookup_single_region($regionId);
    $data['cityId'] = $cityId;
    $data['regionId'] = $regionId;
    $data['store'] = $store;
    
    $this->load->view('map_stores_view', $data);

View: map_stores_view.php
Code:
&lt;?php foreach($store as $sRow){
          echo '<br />'.$sRow->StoreName.'<br />'.$sRow->StoreAddress.'<br />'.$temp_city.', '.$temp_regionName.'<br />'.$sRow->StoreZipCode.'<br />'.$sRow->StorePhoneNumber.'<br />';
          
        }
            
?&gt;

at first, i tried simply calling the store model from the view. this did not work. then, i thought i could trick an array into working by looping through the $store variable before it gets sent, grabbing the collections into an array at position [storeId] and sending the new $collections array, but that didnt work either... though, to be honest, i could have messed up the implementation.

i am simply asking for some advice on a simple fix that i might be missing. a city can have multiple stores, and i need the hascollections info from all of them (connected to the actual store data). the interesting thing is, when you change a little in the view and try to load the model:
Code:
//outside the foreach,
$this->load->model('store');
&lt;?php foreach($store as $sRow){
          echo '<br />'.$sRow->StoreName.'<br />'.$sRow->StoreAddress.'<br />'.$temp_city.', '.$temp_regionName.'<br />'.$sRow->StoreZipCode.'<br />'.$sRow->StorePhoneNumber.'<br />';
          
          $collection = $this->store->lookup_collections_by_store($sRow->StoreId);
          foreach($collection as $colRow){
            //echo '<img >IconPath.'" />';
            echo 'test';
          }
        }

it echos test the right number of times. but when i add .$colRow->IconPath, i get
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$IconPath

Filename: views/map_stores_view.php

Line Number: 33
every time it tries to call $colRow->IconPath

so... what am i missing? should i give the loop in the controller another go? is the model in a view workable? some third thing?

thanks in advance for your help.
#2

[eluser]Mareshal[/eluser]
post here print_r($collection)
#3

[eluser]psolms[/eluser]
thank you. seeing what was in $collection let me figure it out. $IconPath was not in $collection. i knew it would be something stupidly simple like that. Sad

but im glad i got it figured out. thanks again.




Theme © iAndrew 2016 - Forum software by © MyBB