Nieuwe pagina na X aantal records
Hoe zou ik dit het beste aanpakken ? Links, scripts ? Liefst basic :)
Ik werk met Smarty en mijn code ziet er momenteel zo uit (geen poging tot pagina's).
clubs.php
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
include('configs/pdo.inc.php');
include('libs/Smarty.class.php');
// create object
$smarty = new Smarty;
// Clubs ophalen
try {
$query = $oPDO->prepare("SELECT * FROM V_clubs WHERE Zichtbaar = 1 ORDER BY ID ASC LIMIT 10");
$query->execute();
$t = array();
foreach ($query as $row) {
$t[$row['ID']] = $row;
}
$smarty->assign('clubs', $t);
// Categorieen ophalen
$categorie = $oPDO->query("SELECT * FROM t_categorie ORDER BY D_categorie ASC");
$smarty->assign('categorie', $categorie);
// Provincies ophalen
$prov = $oPDO->query("SELECT * FROM t_provincies ORDER BY D_provincie ASC");
$smarty->assign('prov', $prov);
// Clubteller
$xclubs = $oPDO->prepare("SELECT ID from V_clubs");
$xclubs->execute();
} catch (PDOException $e) {
echo '<pre>';
echo 'Regelnummer: ' . $e->getLine() . '<br>';
echo 'Bestand: ' . $e->getFile() . '<br>';
echo 'Foutmelding: ' . $e->getMessage() . '<br>';
echo '</pre>';
}
// display it
$smarty->display('extends:layout.tpl|header.tpl|clubs.tpl|footer.tpl');
?>
include('configs/pdo.inc.php');
include('libs/Smarty.class.php');
// create object
$smarty = new Smarty;
// Clubs ophalen
try {
$query = $oPDO->prepare("SELECT * FROM V_clubs WHERE Zichtbaar = 1 ORDER BY ID ASC LIMIT 10");
$query->execute();
$t = array();
foreach ($query as $row) {
$t[$row['ID']] = $row;
}
$smarty->assign('clubs', $t);
// Categorieen ophalen
$categorie = $oPDO->query("SELECT * FROM t_categorie ORDER BY D_categorie ASC");
$smarty->assign('categorie', $categorie);
// Provincies ophalen
$prov = $oPDO->query("SELECT * FROM t_provincies ORDER BY D_provincie ASC");
$smarty->assign('prov', $prov);
// Clubteller
$xclubs = $oPDO->prepare("SELECT ID from V_clubs");
$xclubs->execute();
} catch (PDOException $e) {
echo '<pre>';
echo 'Regelnummer: ' . $e->getLine() . '<br>';
echo 'Bestand: ' . $e->getFile() . '<br>';
echo 'Foutmelding: ' . $e->getMessage() . '<br>';
echo '</pre>';
}
// display it
$smarty->display('extends:layout.tpl|header.tpl|clubs.tpl|footer.tpl');
?>
clubs.tpl
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{extends file="layout.tpl"}
{block name=title}Clubs{/block}
{block name=content}
<form name="clubsearch" method="POST" action="clubs.php">
<div class="span-6">
<p><label for="categorie">Categorie:</label><br />
<select id="categorie" name="categorie">
<option value="*">Alle disciplines</option>
{foreach $categorie as $c}
<option value="{$c.D_categorie}">{$c.D_categorienaam}</option>
{/foreach}
</select></p>
</div>
<div class="span-4">
<p><label for="provincie" name="provincie">Provincie:</label><br />
<select id="provincie" name="provincie">
<option value="*">Alle provincies</option>
{foreach $prov as $p}
<option value="{$p.D_provincie}">{$p.D_provincienaam}</option>
{/foreach}
</select><p>
</div>
<div class="span-4">
<p><label for="gemeente">Gemeente:</label><br />
<select id="gemeente" name="gemeente">
<option value="*">Alle gemeentes</option>
{foreach $clubs as $c}
<option value="{$c.Gemeente}">{$c.Gemeente}</option>
{/foreach}
</select></p>
</div>
<div class="span-2">
<input type="submit" name="zoekclub" id="zoekclub" value="Zoeken">
</div>
</form>
{if isset($smarty.get.id)}
<div class="span-6 colborder">
<table>
<tr>
<td style="font-weight: bold;">Club</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Naam}</td>
</tr>
<tr>
<td style="font-weight: bold;">Categorie</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Categorie}</td>
</tr>
<tr>
<td style="font-weight: bold;">Provincie</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Provincie}</td>
</tr>
<tr>
<td style="font-weight: bold;">Gemeente</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Gemeente}</td>
</tr>
<tr>
<td style="font-weight: bold;">Website</td>
</tr>
<tr>
<td><a href="{$clubs[$smarty.get.id].Contact}" target="_blank">{$clubs[$smarty.get.id].Contact}</a></td>
</tr>
</table>
</div>
<div class="span-8">
<table>
<tr>
<td style="font-weight: bold;">Info</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Extra}</td>
</tr>
</table>
</div>
{else}
<table>
<tr>
<th>Club</td>
<th>Categorie</td>
<th>Provincie</td>
<th>Gemeente</td>
</tr>
{foreach $clubs as $c}
<tr>
<td><a href="{$SCRIPT_NAME}?id={$c.ID}"><b>{$c.Naam}</b></a></td>
<td>{$c.Categorie}</td>
<td>{$c.Provincie}</td>
<td>{$c.Gemeente}</td>
</tr>
{/foreach}
</table>
{/if}
{/block}
{block name=title}Clubs{/block}
{block name=content}
<form name="clubsearch" method="POST" action="clubs.php">
<div class="span-6">
<p><label for="categorie">Categorie:</label><br />
<select id="categorie" name="categorie">
<option value="*">Alle disciplines</option>
{foreach $categorie as $c}
<option value="{$c.D_categorie}">{$c.D_categorienaam}</option>
{/foreach}
</select></p>
</div>
<div class="span-4">
<p><label for="provincie" name="provincie">Provincie:</label><br />
<select id="provincie" name="provincie">
<option value="*">Alle provincies</option>
{foreach $prov as $p}
<option value="{$p.D_provincie}">{$p.D_provincienaam}</option>
{/foreach}
</select><p>
</div>
<div class="span-4">
<p><label for="gemeente">Gemeente:</label><br />
<select id="gemeente" name="gemeente">
<option value="*">Alle gemeentes</option>
{foreach $clubs as $c}
<option value="{$c.Gemeente}">{$c.Gemeente}</option>
{/foreach}
</select></p>
</div>
<div class="span-2">
<input type="submit" name="zoekclub" id="zoekclub" value="Zoeken">
</div>
</form>
{if isset($smarty.get.id)}
<div class="span-6 colborder">
<table>
<tr>
<td style="font-weight: bold;">Club</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Naam}</td>
</tr>
<tr>
<td style="font-weight: bold;">Categorie</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Categorie}</td>
</tr>
<tr>
<td style="font-weight: bold;">Provincie</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Provincie}</td>
</tr>
<tr>
<td style="font-weight: bold;">Gemeente</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Gemeente}</td>
</tr>
<tr>
<td style="font-weight: bold;">Website</td>
</tr>
<tr>
<td><a href="{$clubs[$smarty.get.id].Contact}" target="_blank">{$clubs[$smarty.get.id].Contact}</a></td>
</tr>
</table>
</div>
<div class="span-8">
<table>
<tr>
<td style="font-weight: bold;">Info</td>
</tr>
<tr>
<td>{$clubs[$smarty.get.id].Extra}</td>
</tr>
</table>
</div>
{else}
<table>
<tr>
<th>Club</td>
<th>Categorie</td>
<th>Provincie</td>
<th>Gemeente</td>
</tr>
{foreach $clubs as $c}
<tr>
<td><a href="{$SCRIPT_NAME}?id={$c.ID}"><b>{$c.Naam}</b></a></td>
<td>{$c.Categorie}</td>
<td>{$c.Provincie}</td>
<td>{$c.Gemeente}</td>
</tr>
{/foreach}
</table>
{/if}
{/block}
Screenshot:
Gewijzigd op 25/06/2011 22:52:24 door Vlad Polianskii
php smarty and pagination
http://www.phpinsider.com/php/code/SmartyPaginate/
Indien iemand een ander idee heeft, hoor ik het graag!