It looks like you're new here. If you want to get involved, click one of these buttons!
$terms['pcd'] = $this->input->post('pcd');
$terms['width'] = $this->input->post('width');
$terms['diameter'] = $this->input->post('diameter');
foreach ($terms as $criteria => $term)
{
$to_model = $criteria.'s_to_products_model';
$this->load->model($to_model);
if ( ! $term)
{
$results[$criteria] = $this->$to_model->find_all();
}
else
{
$results[$criteria] = $this->$to_model->find_all(array($criteria.'_id' => $term));
}
}
foreach ($results[$criteria'] as $product)
{
$listings[] = $product; #if this was an array of the row keyed by id I'd be golden
}
$terms['pcd'] = $this->input->post('pcd');
$terms['width'] = $this->input->post('width');
$terms['diameter'] = $this->input->post('diameter');
foreach ($terms as $criteria => $term)
{
$to_model = $criteria.'s_to_products_model';
$this->load->model($to_model);
if ( ! $term)
{
$results[$criteria] = $this->$to_model->find_all();
}
else
{
$results[$criteria] = $this->$to_model->find_all(array($criteria.'_id' => $term));
}
if ( ! empty($results[$criteria]))
{
foreach ($results[$criteria] as $product)
{
# last query here
$product_ids[] = $product->product_id;
}
}
}
$product_ids = array_unique($product_ids);
if ( ! empty($product_ids))
{
$this->load->model('products_model');
foreach ($product_ids as $product_id)
{
$product_array[] = $this->products_model->find_one_by_id($product_id);
}
}
print_object($product_array); #win.
Comments
To help get around that, you can use the debug_data() method on the model class. Also, for a single returned object, simply doing an echo on it will return the values() of that object (modified the toString object method).
With regards to returning an array using a column as a key, there is a find_all_assoc and a find_all_array_assoc, where the first parameter is the column you want to use as the key for your returned array.
http://www.getfuelcms.com/user_guide/libraries/my_model/table_class_functions
Requirements have changed and I no longer need to store the per criteria results only matches across all so will rewrite.
I noticed in the UG for find_all_assoc() and find_all_array_assoc() it says:
"...The second parameter, assoc_key, will fill the key value ..."
But it's the first parameter. The descriptions are duplicate too, copy paste bug..