[php] Pagination Probleem

Pagina: 1
Acties:
  • 493 views

Onderwerpen


Acties:
  • 0 Henk 'm!

  • lubbertkramer
  • Registratie: Augustus 2009
  • Laatst online: 16:12
Beste gebruikers,

Ik krijg het maar niet werkende om de wallpapers op een pagina te laten tonen met pagination, dit is momenteel mijn code :

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<td class="tableback"> <?php
                     $pagination = new Pagination($limit, $rows, $page, $location);
if(isset($_GET['code'])){
$code=$_GET['code'];
$start = $pagination->prePagination();
$cat = mysql_query("SELECT * FROM iphone WHERE code='".mysql_real_escape_string($code)."'ORDER BY id DESC LIMIT $start, 12");

$rows = mysql_num_rows($cat);

    while($row = mysql_fetch_array($cat)) {    
?>


               <div class="wallpaper-iphonepreview"><a href="achtergrond_iphone4.php?view=<?php echo $row['id']; ?>&naam=<?php echo $row['naam']; ?>"><img class="wallpaper" src="./iphonethumb/<?php echo $row['thumb']; ?>" alt="<?php echo $row['naam']; ?>" /></a>
                     <h4><?php echo $row['naam']; ?></h4>
                     <a class="view-link" href="achtergrond_iphone3.php?view=<?php echo $row['id']; ?>&naam=<?php echo $row['naam']; ?>"><?php echo $row['naam']; ?></a>
                      <a class="view1-link" href="achtergrond_iphone4.php?view=<?php echo $row['id']; ?>&naam=<?php echo $row['naam']; ?>"><?php echo $row['naam']; ?></a></div>
<?php
}
}
?>
<?
$pagination->pagination();
?>


Momenteel werkt het al half, hij laat 12 wallpapers zien, zitten er veel meer in die categorie, maar ik kan niet next en prev aanklikken. Zie --> http://iwallpaper.eu/wallpaper-test.php?page&code=1

Dit is de uitleg van het pagination wat ik gebruik:
This pagination script was designed with modularity in mind. It is extremely easy to add it all over your website without editing any code whatsoever.
To begin, upload all the files and folders located in the “uploads” directory to your site’s main directory or the directory you wish to use pagination.
In your html head tags, add this code snippet:

<link href="PATH/TO/pagination.css" rel="stylesheet" type="text/css" media="screen" />

Make sure you replace the “PATH/TO” to the path where the pagination.css is actually located.

Once the files are uploaded, include this code snippet in the file you wish to use pagination:

define("IN_PAGI", true);
require("PATH/TO/class_pagination.php");
//grab the current page
$page = intval($_GET['page']);
//set the page if empty
if(empty($page))
{
$page = 1;
}

Make sure to change the PATH/TO/ to the actual path location the class_pagination.php file is located.
The above code snippet defines IN_PAGI so the pagination class can run, then we include the pagination
class. The variable page grabs the current page; no need to worry about the URL’s yourself, the .tpl file takes care of that for you. The if control structure checks if the variable page is empty, and sets the
default page, nothing to worry about there.

Next, add this code snippet above where your query to paginate the data (do not grab the data from the query, this is only used to grab the total number of rows returned, read below):
$pagination = new Pagination($limit, $rows, $page, $location);
After instantiating the class, the first parameter takes how many results you want per page.

The second parameter takes the total amount of rows that are pulled out. If you are using MySQL, you run your select query, then a mysql_num_rows function to select the total rows your query grabbed.

That total should be placed in the second parameter.
The third parameter is your current page, leave that set to the $page variable as that is what we used
earlier.

The fourth and last parameter is your current location. In other words, the URL of where you are at WITHOUT a trailing slash. This is used to append the current page to the URL when the pagination runs.

For example, your location could be:
http://yoursite.com/index.php?action=wallpapers
OR
http://yoursite.com/index.php

If it is the first example we used, make sure you add this &page to the end of it as shown below:
http://yoursite...p;amp;page

If it is the second example used, add this ?page to the end of it as shown below:
http://yoursite.com/index.php?page
Now this URL would be the location parameter, the pagination script would do the rest.

Now add this code snippet right before you run your actual query, remember, the other query was just
to grab the total rows, and not to delimit how many rows to display:
$start = $pagination->prePagination();
If you’re using MySQL, add this code snippet to the end of your SQL query:
LIMIT $start, 12

This will set the limit and what data to pull out. Change the number 12 to the number you set on how many rows you want per page.

Now for the final step, add this code snippet to where you want the pagination to appear (make sure
it’s under all the code we just added):
$pagination->pagination();
Success!

You now have your pagination running, follow the same steps except the uploading steps to add the pagination to other parts of your site. If you want to modify the tpl file, read below to learn its
functionalities
Ik heb de maker van het script gecontacteerd, maar mocht niet baten (geen reactie), dus dacht misschien zit iemand hier zo die een fout ziet of iets wat ik verkeerd doe...

Acties:
  • 0 Henk 'm!

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

Ehm, zonder verder de code van prePagination te zien kunnen wij je ook niet helpen. Sterker nog, dat willen we ook niet. We geven geen support op code van anderen. ;)

Wat ik op zich wel zou willen is je gewoon helpen met het zelf maken van je paginering. Dit is echt een simpel rekensommetje waar je de code van deze persoon niet voor nodig hebt. Sowieso:
Warning: Division by zero in /home/admin/domains/iwallpaper.eu/public_html/include/class_pagination.php on line 53
Goeie programmeur is hij dan. :+

Voor paginering is alles wat je moet doen eerst bepalen hoeveel records er zitten in de tabel die voldoen aan je huidige zoekcriteria. Als je dus je query filtert met een where, dan moet je die ook overnemen in een tweede query die zonder limit het aantal records ophaalt met COUNT().

Je hebt dan het paginanummer dat je wil bekijken, want dat haal je al uit $_GET. Je hebt ook het aantal records. Daarnaast moet je weten hoeveel items per pagina je wil laten zien; ik neem aan dat dat er twaalf zijn. Je moet dan de offset berekenen, oftewel $start in je query hierboven.

Dat doe je vrij simpel: de offset is ($page - 1) * $aantal_items_per_pagina + 1. Voor pagina 1 is het dus 1, voor pagina 2 is het 13, enz.

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Acties:
  • 0 Henk 'm!

Verwijderd

Een makkelijk hulpmiddel bij paginering van resultsets is het gebruik van de MySQL functie SQL_CALC_FOUND_ROWS ... waarbij je het totaal aantal rows terugkrijgt ondanks dat je een LIMIT gebruikt.

Verder is het uitrekenen van aantal pagina's enzo zo basic dat ik daar niet op in ga

Acties:
  • 0 Henk 'm!

  • Shadowman
  • Registratie: Januari 2002
  • Niet online
NMe schreef op woensdag 18 augustus 2010 @ 13:06:
Goeie programmeur is hij dan. :+
nah, denk dat ie niet verwacht in zijn code dat het aantal items per pagina's dat opgegeven wordt 0 is (en aangezien de TS al verwijst naar een variabele die pas 6 regels later wordt gedefinieerd gok ik zo dat $limit niet gezet is). Maakt dat iemand een slechte programmeur (je mag toch wel iets verwachten van de mensen die gebruikmaken van de class lijkt me zo)?

Verder niets toe te voegen en ken die class verder ook niet.

Acties:
  • 0 Henk 'm!

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

Shadowman schreef op woensdag 18 augustus 2010 @ 13:20:
[...]

nah, denk dat ie niet verwacht in zijn code dat het aantal items per pagina's dat opgegeven wordt 0 is (en aangezien de TS al verwijst naar een variabele die pas 6 regels later wordt gedefinieerd gok ik zo dat $limit niet gezet is). Maakt dat iemand een slechte programmeur (je mag toch wel iets verwachten van de mensen die gebruikmaken van de class lijkt me zo)?
Auw, die was me niet eens opgevallen.

lubbertkramer: lees jij boeken altijd in willekeurige volgorde of netjes van begin tot eind? De PHP-interpreter is niet anders. ;)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Acties:
  • 0 Henk 'm!

  • lubbertkramer
  • Registratie: Augustus 2009
  • Laatst online: 16:12
Verwijderd schreef op woensdag 18 augustus 2010 @ 13:12:
Een makkelijk hulpmiddel bij paginering van resultsets is het gebruik van de MySQL functie SQL_CALC_FOUND_ROWS ... waarbij je het totaal aantal rows terugkrijgt ondanks dat je een LIMIT gebruikt.

Verder is het uitrekenen van aantal pagina's enzo zo basic dat ik daar niet op in ga
Nadeel hiervan is dat de query langer duurt/meer belasting heeft
NMe schreef op woensdag 18 augustus 2010 @ 13:22:
[...]

Auw, die was me niet eens opgevallen.

lubbertkramer: lees jij boeken altijd in willekeurige volgorde of netjes van begin tot eind? De PHP-interpreter is niet anders. ;)
Script was aangekocht op codecanyon (leek mij een goed script) alleen helaas na het lezen van hoe/wat krijg ik het dus niet voor elkaar.

Acties:
  • 0 Henk 'm!

  • ajakkes
  • Registratie: Maart 2004
  • Laatst online: 16-05 22:32

ajakkes

👑

Volgens mij doelen ze op:

"If you’re using MySQL, add this code snippet to the end of your SQL query:
LIMIT $start, 12

This will set the limit and what data to pull out. Change the number 12 to the number you set on how many rows you want per page."

Wat halverwege in de handleiding staat.

👑


Acties:
  • 0 Henk 'm!

  • lubbertkramer
  • Registratie: Augustus 2009
  • Laatst online: 16:12
ajakkes schreef op woensdag 18 augustus 2010 @ 13:38:
Volgens mij doelen ze op:

"If you’re using MySQL, add this code snippet to the end of your SQL query:
LIMIT $start, 12

This will set the limit and what data to pull out. Change the number 12 to the number you set on how many rows you want per page."

Wat halverwege in de handleiding staat.
Dat heb ik toegevoegd in mijn mysql query zoals je kan zien in de code die ik in het start topic had neergezet, hij laat ook netjes 12 zien, alleen geen next of prev

Acties:
  • 0 Henk 'm!

  • EddoH
  • Registratie: Maart 2009
  • Niet online

EddoH

Backpfeifengesicht

Lubbert,

kijk eens goed naar:

PHP:
1
2
<td class="tableback"> <?php
                     $pagination = new Pagination($limit, $rows, $page, $location);


welke waarden zullen $limit, $rows, $page, $location daar hebben?

Acties:
  • 0 Henk 'm!

  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 21:47

Creepy

Tactical Espionage Splatterer

Als je script is aangekocht, dan zul je bij de partij moeten zijn die je script heeft gemaakt. Hier in PRG draait het om het zelf ontwikkelen van software. Als je iets hebt gedownload, en het bevat fouten, dan lijkt het me verstandiger dat je daar support gaat geven. Zoals NMe al aangeeft kunnen we je wel proberen te helpen puur met pagination, en dat je dat dan zelf gaat maken. Dat lijk je niet te willen doen aangezien je blijft doorgaan met je gedownloade script. Dat is niet erg, maar dan is PRG, of het hele forum hier, gewoon niet de juiste plek.

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney

Pagina: 1

Dit topic is gesloten.