[opgelost]mysql omzetten in mysqli(aantal pagina's per x-weergaves)
Ik probeer nu het script om te zetten van mysql naar mysqli, maar het lukt niet helemaal.
Ik heb het idee dat de fout meer zit in :
maar heb geen idee hoe ik dat omzet naar mysqli. (mysqli_result() geeft iets aan, dat het niet bestaat).
Als ik gebruik maak van mysqli_num_rows(), dan geeft die 1 aan.
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
100
101
102
103
104
105
106
107
108
109
110
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
100
101
102
103
104
105
106
107
108
109
110
<?php
require_once('config.php');
$postsPerPage = 25; // het aantal iterms dat je per pagina wil laten zien
$numPageNumbers = 100; // het aantal pagina nummers dat word laten zien
$sql = $connect-> query("SELECT COUNT(*) AS num FROM grandexchange WHERE icon='ja' ORDER BY item_id ASC");
$totalRecords = mysql_result($sql, 0, 'num');
echo 'records: '.$totalRecords;
// het aantal pagina nummers uitrekenen
$totalPages = ceil($totalRecords / $postsPerPage);
$currentPage = isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0 && $_GET['page'] <= $totalPages ? $_GET['page'] : 1;
if($totalPages > $numPageNumbers)
{
$pageNumberStart = $currentPage - floor($numPageNumbers / 2);
$pageNumberEnd = $currentPage + floor($numPageNumbers / 2);
while($pageNumberStart < 1) { $pageNumberStart++; $pageNumberEnd++; }
while($pageNumberEnd > $totalPages) { $pageNumberStart--; $pageNumberEnd--; }
}
else
{
$pageNumberStart = 1;
$pageNumberEnd = $totalPages;
}
$offset = ($currentPage - 1) * $postsPerPage;
$sql = $connect->query("SELECT * FROM `grandexchange` WHERE icon='ja' ORDER BY `item_id` ASC LIMIT ".$offset.", ".$postsPerPage);
?>
<?php
$data = array();
if(mysqli_num_rows($sql))
{
while($row = mysqli_fetch_array($sql))
{
$data[] = $row;
}
}
?>
<table id="hor-minimalist-b" summary="Employee Pay Sheet">
<thead>
<tr>
<th scope="col" width="30px"></th>
<th scope="col" width="200px">Item</th>
<th scope="col" width="600px"><div style="text-align:right;">Price</div></th>
</tr>
</thead><tbody>
<?php
if($data)
{
foreach($data as $row)
{
echo '
<tr>
<td><img src=images/sprites/'.$row['icon_url'].' ??/></td>
<td><a href="item.php?item_id='.$row['item_id'].'">'.$row['item_name'].'</a></td>
<td><div class="stats"><div class="itemprice"><ul>'.number_format($row['price']).'GP</div><div style="clear:both;"></div><li><span class="'.$row['status'].'">'.$row['price_change'].'%</span></li></ul></div></td>
</tr>
';
}
echo '<ul class="pagination">';
if($pageNumberStart > 1)
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?page=1" title="pagina 1">...</a></li>';
for($i=$pageNumberStart; $i<=$pageNumberEnd; $i++)
echo $i == $currentPage ? '<li><strong>'.$i.'</strong></li>' : '<li><a href="'.$_SERVER['PHP_SELF'].'?&page='.$i.'" title="pagina '.$i.'">'.$i.'</a></li>';
if($pageNumberEnd < $totalPages)
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?page='.$totalPages.'" title="pagina '.$totalPages.'">...</a></li>';
echo '</ul>';
}
else
{
echo '<center><p>no items fout</p></center>';
}
?>
require_once('config.php');
$postsPerPage = 25; // het aantal iterms dat je per pagina wil laten zien
$numPageNumbers = 100; // het aantal pagina nummers dat word laten zien
$sql = $connect-> query("SELECT COUNT(*) AS num FROM grandexchange WHERE icon='ja' ORDER BY item_id ASC");
$totalRecords = mysql_result($sql, 0, 'num');
echo 'records: '.$totalRecords;
// het aantal pagina nummers uitrekenen
$totalPages = ceil($totalRecords / $postsPerPage);
$currentPage = isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0 && $_GET['page'] <= $totalPages ? $_GET['page'] : 1;
if($totalPages > $numPageNumbers)
{
$pageNumberStart = $currentPage - floor($numPageNumbers / 2);
$pageNumberEnd = $currentPage + floor($numPageNumbers / 2);
while($pageNumberStart < 1) { $pageNumberStart++; $pageNumberEnd++; }
while($pageNumberEnd > $totalPages) { $pageNumberStart--; $pageNumberEnd--; }
}
else
{
$pageNumberStart = 1;
$pageNumberEnd = $totalPages;
}
$offset = ($currentPage - 1) * $postsPerPage;
$sql = $connect->query("SELECT * FROM `grandexchange` WHERE icon='ja' ORDER BY `item_id` ASC LIMIT ".$offset.", ".$postsPerPage);
?>
<?php
$data = array();
if(mysqli_num_rows($sql))
{
while($row = mysqli_fetch_array($sql))
{
$data[] = $row;
}
}
?>
<table id="hor-minimalist-b" summary="Employee Pay Sheet">
<thead>
<tr>
<th scope="col" width="30px"></th>
<th scope="col" width="200px">Item</th>
<th scope="col" width="600px"><div style="text-align:right;">Price</div></th>
</tr>
</thead><tbody>
<?php
if($data)
{
foreach($data as $row)
{
echo '
<tr>
<td><img src=images/sprites/'.$row['icon_url'].' ??/></td>
<td><a href="item.php?item_id='.$row['item_id'].'">'.$row['item_name'].'</a></td>
<td><div class="stats"><div class="itemprice"><ul>'.number_format($row['price']).'GP</div><div style="clear:both;"></div><li><span class="'.$row['status'].'">'.$row['price_change'].'%</span></li></ul></div></td>
</tr>
';
}
echo '<ul class="pagination">';
if($pageNumberStart > 1)
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?page=1" title="pagina 1">...</a></li>';
for($i=$pageNumberStart; $i<=$pageNumberEnd; $i++)
echo $i == $currentPage ? '<li><strong>'.$i.'</strong></li>' : '<li><a href="'.$_SERVER['PHP_SELF'].'?&page='.$i.'" title="pagina '.$i.'">'.$i.'</a></li>';
if($pageNumberEnd < $totalPages)
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?page='.$totalPages.'" title="pagina '.$totalPages.'">...</a></li>';
echo '</ul>';
}
else
{
echo '<center><p>no items fout</p></center>';
}
?>
Gewijzigd op 17/11/2014 19:25:09 door Marco Eilander
Je bent nog niet klaar want ik zie nog mysql_ tussen de mysqli_ functions.
- SanThe - op 16/11/2014 16:44:42:
Je bent nog niet klaar want ik zie nog mysql_ tussen de mysqli_ functions.
Waar precies? Dat regel 11 nog niet klopt, dat wist ik. ;)
Foutafhandeling zelf toevoegen. ;-)