0

I have coded this : get_post

This is my get_post function, that gets data. Function results();

So there is more than one row.

show_post

And here is function that shows post, loading view and putting this data from get_post function.

But this isn't a single row. This is an array... enter image description here

Here is var_dump of this array

I do not know how to work with this array inside view.

For example

...
...<a href="#"><?php echo $tytul; ?></a>...
...

Doens't work.

I don't know how to use this array.

How to get into it's elements?

How to loop them? How to get for example title from 2 row? Or loop all rows to get all "url" that it contains?

0

3 Answers 3

1

in controller set a name for your data

$this-load->view('post', array('posts'=>$post));

in view use that name of the array

foreach($posts as $post) {
    ...<a href="#"><?php echo $post->tytul; ?></a> 
Sign up to request clarification or add additional context in comments.

Comments

0

Use bellow code to get you data from controller to view:

$post['postinfo'] = $this->Devloger->get_post($url);
$this-load->view('post', array('posts'=>$post));

Try to print array in the view side:

print_r($postinfo);

you will get all the data in the view. You can get particular value from the array with its key.

$postinfo[0]->title

Hope this will help you!

Greetings!

Comments

0
Write code in your controller set $data as public and you can use $data using $this->data['set variable name accessing in view with this name'];

$data you can use in all post controller function    
post.php //your controlle
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Post extends MY_Controller {   
public $data;
public function __construct() {
parent::__construct();
}

 private function show_post(){
  $this->data['posts'] = $this->Devloger->get_post($url);   
 $this-load->view('post',$this->data['posts']);  
 }

post.php
foreach($posts as $post){  
 echo $post['title'];  
 }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.