Welcome Guest, Not a member yet? Register   Sign In
Can you check my pagination?[SOLVED]
#7

(02-09-2017, 08:56 AM)Wouter60 Wrote: In your controller, you first have $data['blog'] = ... to get all records from the blog via the model.
In the pagination part, you have $data['results'] = .... to get only the records for the specified page.
The foreach { } part in the view refers to $blog. That's why it shows all records, regardless of the pagination settings. Replace it with $results.
Besides that, don't loop through a foreach with foreach ($blog as $blog). Better is:
PHP Code:
Foreach($results as $result) {
 
 

$results: prural (is a collection of objects or arrays)
$result: single (is a single object or array)

I did that on my view as you said, but nows it shows another error:

Home Blog

A PHP Error was encountered
[/url]Severity: Error
Message: Cannot use object of type stdClass as array
Filename: blog/index.php
Line Number: 15
Backtrace:


Here is my view as you wanted me to do:

PHP Code:
<?php foreach($results as $result ?>
<div class="card text-xs-left"><!-- FIRST ARTICLE DEMO -->
<div class="card-header" id="article-header">
<h4><a href="<?php echo site_url('/blog/'.$result['slug']); ?>"><?php echo ucfirst($result['titulo']); ?></a></h4>
</div>
<img src="<?php echo $result['imagen']; ?>" width="750" heihgt="350" class="img-fluid">
<!--<div class="card-body">
<p> <?php  echo word_limiter($result['contenido'],5); ?></p>
</div>-->
<div class="card-footer" id="article-footer">
<div class="row">
<div class="col-lg-12 col-md-9 col-sm-8">
<i class="fa fa-calendar" aria-hidden="true"></i> <?php echo ucfirst($result['fecha']); ?> 

<i class="fa fa-folder" aria-hidden="true"></i> <?php echo $result['categoria_id']; ?> 

<a href="<?php echo site_url('/blog/'.$result['slug']); ?>" class="pull-right">Read more »</a>
</div>
</div>
</div>
</div>
<?php ?>

[url=http://localhost/demo6/blog/%3Cbr%20/%3E%3Cb%3EFatal%20error%3C/b%3E:%20%20Cannot%20use%20object%20of%20type%20stdClass%20as%20array%20in%20%3Cb%3EC:/xampp2/htdocs/demo6/application/views/news/blog/index.php%3C/b%3E%20on%20line%20%3Cb%3E15%3C/b%3E%3Cbr%20/%3E%3Cdiv%20style=]Bythe way, thanks for wanting to help, I'm grateful that somebody is actually trying to help me with this.
I do Front-End development most of the time 
Reply


Messages In This Thread
RE: Can you check my pagination? - by Wouter60 - 02-08-2017, 11:48 PM
RE: Can you check my pagination? - by kirasiris - 02-09-2017, 12:53 AM
RE: Can you check my pagination? - by Wouter60 - 02-09-2017, 05:42 AM
RE: Can you check my pagination? - by kirasiris - 02-09-2017, 06:12 AM
RE: Can you check my pagination? - by Wouter60 - 02-09-2017, 08:56 AM
RE: Can you check my pagination? - by kirasiris - 02-09-2017, 06:25 PM
RE: Can you check my pagination? - by Wouter60 - 02-09-2017, 11:40 PM
RE: Can you check my pagination? - by kirasiris - 02-10-2017, 12:50 PM
RE: Can you check my pagination? - by pdthinh - 02-10-2017, 10:01 PM
RE: Can you check my pagination? - by kirasiris - 02-10-2017, 10:46 PM
RE: Can you check my pagination? - by pdthinh - 02-10-2017, 11:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB