PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 11, 2022

[FIXED] Using serial number with paginate

 March 11, 2022     laravel, laravel-5, php     No comments   

Issue

I am trying to retrieve serial number in the blade template with variable i:

    <?php $i=0;?>
    @foreach ($lists as $li)
    <tr><td><?php $i++;?>{{$i}}</td><td>{{$li->Name}}</td><td>{{$li->Telephone}}
    </td><td>{{$li->mobile}}</td>
    @endforeach
    {!! $lists->render() !!}

but I am using paginate in the controller:

$lists=telephone::orderBy('name')->simplePaginate(10);

So, the first page's serial number is ok. But for the second page i starts from 1 again.


Solution

UPDATE:

The solution below starts from 0 instead of 1 for the first page. To start from 1:

$i = ($lists->perPage() * ($lists->currentPage() - 1)) + 1;

Try setting $i to $lists->perPage() * ($lists->currentPage() - 1)

$i = $lists->perPage() * ($lists->currentPage() - 1);


Answered By - Doom5
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing