[eluser]Unknown[/eluser]
Okey so, the heading was pretty decent, haha, agree?
The problem is: I have 5 different tables with pictures which I am outputting to view using a massive bunch of array within array techniques to the 1 view, which i call home_page! So, here is the code, can you suggest me a better way(A) and also, how to print the data or transport the related data of those particular images along with the arrays. I CANT! The problems are 1) 5 tables and 2) Different Table schema.
Code:
function members_area() {
/////
$this->load->model('register_model');
$result1= $this->register_model->get_images();
$result2= $this->register_model->get_woman();
$result3= $this->register_model->get_combo();
$result4= $this->register_model->get_themes();
$result5= $this->register_model->get_spy();
$num_rows_feeds = $result1->num_rows() + $result2->num_rows() + $result3->num_rows() + $result4->num_rows() + $result5->num_rows();
$data=FALSE;
$tmparr = array();
foreach ($result1->result_array() as $row)
{
$tmparr[] = $row['girl'];
//$parr[] = $row['id'];
//$parr[] = $row['table_name'];
//$data['num_rows_feeds'][] = $num_rows_feeds;
//var_dump($tmparr);
}
foreach ($result2->result_array() as $row)
{
$tmparr[] = $row['pic1'];
$tmparr[] = $row['pic2'];
$tmparr[] = $row['pic3'];
$tmparr[] = $row['pic4'];
//$parr[] = $row['id'];
//$parr[] = $row['table_name'];
//$data['num_rows_feeds'][] = $num_rows_feeds;
//var_dump($tmparr);
}
foreach ($result3->result_array() as $row)
{
$tmparr[] = $row['pic1'];
$tmparr[] = $row['pic2'];
$tmparr[] = $row['pic3'];
$tmparr[] = $row['pic4'];
//$parr[] = $row['id'];
//$parr[] = $row['table_name'];
//$data['num_rows_feeds'][] = $num_rows_feeds;
//var_dump($data);
}
foreach ($result4->result_array() as $row)
{
$tmparr[] = $row['pic1'];
$tmparr[] = $row['pic2'];
$tmparr[] = $row['pic3'];
$tmparr[] = $row['pic4'];
//$parr[] = $row['id'];
//$parr[] = $row['table_name'];
//$data['num_rows_feeds'][] = $num_rows_feeds;
//var_dump($data);
}
foreach ($result5->result_array() as $row)
{
$tmparr[] = $row['pic1'];
$tmparr[] = $row['pic2'];
$tmparr[] = $row['pic3'];
$tmparr[] = $row['pic4'];
//$parr[] = $row['id'];
//$parr[] = $row['table_name'];
//$data['num_rows_feeds'][] = $num_rows_feeds;
//var_dump($data);
}
$outarr = array();
$i = 0; //$j = 0; $s = 0;
foreach($tmparr as $url){
if(strpos($url, 'http') !== false){
$outarr[] = array('origimage'=>$url,'thumb'=>substr($url,0,strripos($url,'/',0)).'/thumbs/'.substr($url,strripos($url,'/',0)+1));
$i++;
}
} //$j++;
$data['num_rows_feeds'] = $i;
$data['data'] = $outarr;
//var_dump($data);
$to_nav['user'] = $this->session->userdata('spotter_name');
$this->load->view('header');
$this->load->view('navigation_view',$to_nav);
$this->load->view('home_page',$data);
$this->load->view('footer');
}
---
View
Code:
<?php
if (isset($data) && !empty($data) && is_array($data)) {//2
$i = 0;
$entries = array();
while(array_key_exists($i, $data)) {//1
$entries[$i] = '<a href="'.$data[$i]['origimage'].'"> <img src="'.$data[$i]['origimage'].'" width="120" height="150"/> </a>';
//$entries[$i].= '<p>' .$data[$i]['id'] .'</p>';
//$entries[$i] = '<p>'.$data[$i]['origimage'].'</p>';
echo $entries[$i];
$i++;
}//1
}//2
?>
Quick Edit: Essentially, you can use this for example, like I have to print ID of tables under the images, and then a different field for each of them, like for girl I would want to print spotter_name, for woman, I would print country.