I am accessing an array object being transferred from model to view. When I print that array it shows complete info what I want, but when I implement foreach on that array and try to access an index it gives me an error of undefined index.
the model code is
public function fetch()
{
$queryy=$this->db->select('*')
->from('selleritem')
->get();
$data=$queryy->result();
foreach($data as $datas)
{
$pid=$datas->pid ;
$query= $this->db->limit('1')
->select('*')
->where('pid', $pid)
->get('selleritemimages');
if($query->num_rows() > 0){
foreach ($query->result() as $row)
{
$data[] = $row;
}
return $data;
//print_r($data);
}
}
the controller code is:
public function index()
{
$this->load->model('fetchindex');
$fetch= array($this->fetchindex->fetch());
$this->load->view('welcome_message',['fetch'=>$fetch]);
}
}
the view code is printing the array in view shows .
print_r($fetch);
foreach ( $fetch as $ff) {
echo $ff["pid"].'hh<br>';
}
printing the array in view shows .
Array (
[0] => Array
(
[0] => stdClass Object
(
[id] => 2
[name] => fashionable kurta for men
[gender] => groom
[price] => 11213
[description] => Item Description
[rent_sale] => Rent
[features] => Key Features
[pid] => 4
[product] => kurta
[available] => 9
[uid] => 2
[ucid] => 7
[rating] => 0
[rating_users] => 0
)
[1] => stdClass Object
(
[id] => 1
[name] => suit fro groom
[gender] => groom
[price] => 12345
[description] => Item Description
[rent_sale] => Sale
[features] => Key Features
[pid] => 3
[product] => suits
[available] => 6
[uid] => 2
[ucid] => 11
[rating] => 22
[rating_users] => 5
)
[2] => stdClass Object
(
[id] => 3
[name] => sherwani
[gender] => groom
[price] => 12133
[description] => Item Description
[rent_sale] => Rent
[features] => Key Features
[pid] => 5
[product] => sherwani
[available] => 10
[uid] => 4
[ucid] => 10
[rating] => 22
[rating_users] => 5
)
[3] => stdClass Object
(
[id] => 4
[name] => branded shoes for groom
[gender] => groom
[price] => 3232
[description] => Item Description
[rent_sale] => sale
[features] => Key Features
[pid] => 6
[product] => foot wear
[available] => 9
[uid] => 4
[ucid] => 12
[rating] => 22
[rating_users] => 5
)
[4] => stdClass Object
(
[id] => 5
[name] => watches for groom
[gender] => groom
[price] => 33232
[description] => Item Description
[rent_sale] => Sale
[features] => Key Features
[pid] => 7
[product] => watches
[available] => 10
[uid] => 2
[ucid] => 18
[rating] => 24
[rating_users] => 6
)
[5] => stdClass Object
(
[id] => 6
[name] => watches for groom
[gender] => groom
[price] => 12133
[description] => Item Description
[rent_sale] => Sale
[features] => Key Features
[pid] => 8
[product] => watches
[available] => 10
[uid] => 1
[ucid] => 18
[rating] => 22
[rating_users] => 5
)
[6] => stdClass Object
(
[id] => 9
[name] => Branded bags
[gender] => bride
[price] => 22353
[description] => branded bags for sale
[rent_sale] => Sale
[features] => branded bags for sale
[pid] => 9
[product] => bags
[available] => 7
[uid] => 1
[ucid] => 3
[rating] => 53
[rating_users] => 20
)
[7] => stdClass Object
(
[id] => 10
[name] => Branded bags
[gender] => bride
[price] => 22353
[description] => Item Description
[rent_sale] => Sale
[features] => Key Features
[pid] => 10
[product] => bags
[available] => 8
[uid] => 1
[ucid] => 3
[rating] => 39
[rating_users] => 16
)
[8] => stdClass Object
(
[id] => 11
[image] => 1582863614kurta.jpg
[pid] => 4
[uid] => 2
)
)
)
Below is the error what I'm getting:
Severity: Notice Message: Undefined index: pid Filename: views/welcome_message.php Line Number: 33