Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 12:16

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Pagination - wie Daten ausgeben?

Discussion on Pagination - wie Daten ausgeben? within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2014
Posts: 276
Received Thanks: 84
Pagination - wie Daten ausgeben?

Hallo Epvp'ler. Ich stehe gerade extrem auf dem Schlauch. Ich würde gerne Pagination von Bootstrap nutzen.
PHP Code:
 <nav>
  <
ul class="pagination">
    <
li>
      <
a href="#" aria-label="Previous">
        <
span aria-hidden="true">&laquo;</span>
      </
a>
    </
li>
    <
li><a href="#">1</a></li>
    <
li><a href="#">2</a></li>
    <
li><a href="#">3</a></li>
    <
li><a href="#">4</a></li>
    <
li><a href="#">5</a></li>
    <
li>
      <
a href="#" aria-label="Next">
        <
span aria-hidden="true">&raquo;</span>
      </
a>
    </
li>
  </
ul>
</
nav
Aber ich kriegs gerade irgendwie nicht in meinen Kopf, wie ich zb pro Seite 9 einträge aus der Datenbank anzeigen lassen kann, hat da jemand ne Idee?
.Barone
.Barone is offline  
Old 02/16/2016, 19:05   #2

 
~ JWonderpig ~'s Avatar
 
elite*gold: 60
Join Date: Sep 2013
Posts: 1,427
Received Thanks: 248
Das geht ganz einfach mit SQL. Einfach immer das Limit 9 setzen und durch die aktuelle Seite den Offset für eine SQL Query errechnen.

Ich habe hier noch eine PHP Klasse, die ich ab und zu nutze.

1. Parameter: 9
2. Parameter: Gesamtzahl aller Rows
3. Parameter: Aktuelle Seite (z.b. durch $_GET übergeben)

Danach einfach die Methode getPageInfo aufrufen und du kannst dir damit die Pagination generieren.

PHP Code:
class Paginator
{

    private 
$totalPages;
    private 
$page;
    private 
$limit;

    
/**
     * @param int $entriesPerPage How many items should be displayed
     * @param int $count How many items are there?
     * @param int $page Current page
     */
    
public function __construct($entriesPerPage$count$page)
    {
        
$this->limit = (int) $entriesPerPage;
        
$this->page = (int) $page;
        
$this->totalPages ceil((int) $count/$this->limit);
    }

    
/**
     * Returns an array with all information
     *
     * @return array
     */
    
public function getPageInfo()
    {
        return array(
            
'totalPages' => $this->totalPages,
            
'currentPage' => $this->page,
            
'limit' => $this->limit,
            
'offset' => $this->calculateOffset(),
        );
    }

    private function 
calculateOffset()
    {
        return (
$this->page 1) * $this->limit;
    }


~ JWonderpig ~ is offline  
Old 02/17/2016, 18:34   #3
dotCom
 
Devsome's Avatar
 
elite*gold: 9842
The Black Market: 107/0/0
Join Date: Mar 2009
Posts: 16,866
Received Thanks: 4,685
Ich kann dir das nur empfehlen
Würde so aussehen

Code:
<link rel="stylesheet" href="/dataTables.bootstrap.min.css">
Code:
<div class="dataTable_wrapper">
	<table class="table table-striped table-bordered table-hover" id="news-table">
		<thead>
			<tr>
				<th>{{ trans('admin/news/default.show_table_id') }}</th>
				<th>{{ trans('admin/news/default.show_table_title') }}</th>
				<th>{{ trans('admin/news/default.show_table_created_at') }}</th>
				<th>{{ trans('admin/news/default.show_table_published_on') }}</th>
			</tr>
		</thead>
		<tbody>
			@foreach($news as $msg)
			<tr>
				<td>{{ $msg->id }}</td>
				<td>{{ $msg->title }}</td>
				<td>{{ $msg->created_at }}</td>
				<td>{{ $msg->published_at }}</td>
			</tr>
			@endforeach
		</tbody>
	</table>
</div>
Ist mit dem Template gemacht

//Edit: Script vergessen

Code:
<script src="/js/jquery.dataTables.min.js"></script>
<script src="/js//dataTables.bootstrap.min.js"></script>
<script>
  $(document).ready(function() {
	 $('#news-table').DataTable({
		"columnDefs": [
		   {
			  "targets": [ 2 ],
			  "searchable": false,
		   },
		   {
			  "targets": [ 3 ],
			  "searchable": false
		   },
		   {
			  "targets": [ 4 ],
			  "searchable": false,
			  "orderable": false
		   },
		   {
			  "targets": [ 5 ],
			  "searchable": false,
			  "ordering": false,
			  "orderable": false
		   }
		],
		responsive: true
	 });
  });
</script>
Devsome is offline  
Reply


Similar Threads Similar Threads
Für wow geld ausgeben oder für free to play games geld ausgeben?
09/22/2013 - General Gaming Discussion - 5 Replies
Hallo, was meint ihr sollte man für freetoplay spiel, wo paytowin herrscht, dafür sein Geld ausgeben, damit man für eine permanente (Beispiel) waffe 25€ ausgibt oder sollte man das Geld lieber in wow reinstecken und halt nur ne begrenzte Zeit spielen, man kann bei freetoplay ja immer spielen, aber bei wow hast du ja alle "Waffen" für immer, also was meint ihr sollte man in wow das Geld reinstecken oder eher in ein paytowin system es reinsteken? :)
[B] 2LT ³ mit allen Daten & Permanenten Waffen an Und einen Ohne Daten!
11/25/2012 - Combat Arms Trading - 26 Replies
Hi liebe leute , da ich kein Combat Arms mehr spiele, habe ich beschlossen meine zwei restlichen Account's los zu werden. 1. 2LT (Goldene Pommer) ³ mit 20%+ Ist (Male) der Glatzkopf besitzt noch 3 Mepaphone und einmal Base Charakter Change. Die Permanenten Waffen bei ihm sind : G36e Valkyrie und Arctic Wolf ( Der Account war nie vorbestraft / gebannt / aufgefallen ) MIT KEINEN MEINER ACCOUNTS DIE ICH HIER ANBIETE WURDE GEHACKT! Er besitzt noch über 130.000+ GP. Ich kenne alle...
[C#] MySQL Daten in Textbox ausgeben!
07/26/2012 - .NET Languages - 4 Replies
Hey ich arbeite derzeit an einem Tool für meine GMs, es ist fast fertig nur fehlt mir noch eine sache undzwar, möchte ich bestimmte Daten aus der Datenbank in eine Textbox ausgeben (Die Daten haben einen INT wert also Zahlen) nur ist mir garnicht klar wie das gehen soll. DataTable datatable = new DataTable(); String sql1 = "SELECT * FROM t_characters user_code WHERE a_nick =" + textBox1.Text; MySqlDataAdapter dataAdapter = new MySqlDataAdapter(sql1, connection); ...



All times are GMT +1. The time now is 12:18.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.