07-26-2000, 04:13 PM
Well, here is my first vB hack. I have not cut any code for a long time so that if anyone wants to clean up my PHP, please feel free to comment. I do wonder if there is a way to get the total number of records without a second query; I thought of counting to see if fewer than 30 (my page limit) smilies were returned, but then I would have to give up the "First to Last of Total" report.
I added the following variables: $startsmilies, $smilieslink, $linkstartsmilies, $smiliescountresult, $smiliescountrow and $smiliescount
Any way:
Replace the section in index.php (the main one, not the /admin/ one) that deals with "action=showsmilies" -- I have not posted it here as all my code has been added between the start and end of the section so that it should be simple for you to find (lines 44 to 56 in an un-hacked index.php).
if ($action=="showsmilies") {
// 2000-07-26 PEH - hacked to add LIMIT clause to break up ShowSmilies page
if (!isset($startsmilies)) {
$startsmilies=0;
}
// added LIMIT statement, hard coded "30" as the per page value
// (should move this to a variable in the control panel, though)
$smilies=$DB_site->query("SELECT smilietext,title,smiliepath FROM smilie ORDER BY title LIMIT $startsmilies,30");
while ($smilie=$DB_site->fetch_array($smilies)) {
$smilietext=$smilie[smilietext];
$smiliepath=$smilie[smiliepath];
$title=$smilie[title];
eval("\$smiliebits .= \"".gettemplate("smiliebit")."\";");
}
// $smilieslink sets up the page links, if needed
$smilieslink = "";
// display a link to the previous page, if needed
if ($startsmilies>29) {
$linkstartsmilies=$startsmilies-30;
$smilieslink .= "<a href=\"index.php?action=showsmilies&startsmilies=$linkstartsmilies\">Previous</a> / ";
}
// $smiliescount is the total number of smilies in the database
$smiliescountresult=$DB_site->query("SELECT COUNT(*) AS Total FROM smilie");
$smiliescountrow=$DB_site->fetch_array($smiliescountresult);
$smiliescount=$smiliescountrow["Total"];
// display the current range for information only
$smilieslink .= "Smilies " . ($startsmilies+1) . " to " . min(($startsmilies+30),($smiliescount+0)) . " of " . $smiliescount;
// display a link to the next page, if needed
if ($startsmilies<$smiliescount-30) {
$linkstartsmilies=$startsmilies+30;
$smilieslink .= " / <a href=\"index.php?action=showsmilies&startsmilies=$linkstartsmilies\">Next</a>";
}
eval("echo dovars(\"".gettemplate("smilies")."\");"); // added line to "smilies" to show link to previous and/or next page
}
In the "smilies" template you have to add the "$smilieslink" variable wherever you want your Previous/Next links to appear. I put mine after the table closes but before the centering closes:
$smiliebits
</table>
$smilieslink
</center>
Peter E. Humphries
[Edited by phumphries on 07-26-2000 at 01:14 PM]
I added the following variables: $startsmilies, $smilieslink, $linkstartsmilies, $smiliescountresult, $smiliescountrow and $smiliescount
Any way:
Replace the section in index.php (the main one, not the /admin/ one) that deals with "action=showsmilies" -- I have not posted it here as all my code has been added between the start and end of the section so that it should be simple for you to find (lines 44 to 56 in an un-hacked index.php).
if ($action=="showsmilies") {
// 2000-07-26 PEH - hacked to add LIMIT clause to break up ShowSmilies page
if (!isset($startsmilies)) {
$startsmilies=0;
}
// added LIMIT statement, hard coded "30" as the per page value
// (should move this to a variable in the control panel, though)
$smilies=$DB_site->query("SELECT smilietext,title,smiliepath FROM smilie ORDER BY title LIMIT $startsmilies,30");
while ($smilie=$DB_site->fetch_array($smilies)) {
$smilietext=$smilie[smilietext];
$smiliepath=$smilie[smiliepath];
$title=$smilie[title];
eval("\$smiliebits .= \"".gettemplate("smiliebit")."\";");
}
// $smilieslink sets up the page links, if needed
$smilieslink = "";
// display a link to the previous page, if needed
if ($startsmilies>29) {
$linkstartsmilies=$startsmilies-30;
$smilieslink .= "<a href=\"index.php?action=showsmilies&startsmilies=$linkstartsmilies\">Previous</a> / ";
}
// $smiliescount is the total number of smilies in the database
$smiliescountresult=$DB_site->query("SELECT COUNT(*) AS Total FROM smilie");
$smiliescountrow=$DB_site->fetch_array($smiliescountresult);
$smiliescount=$smiliescountrow["Total"];
// display the current range for information only
$smilieslink .= "Smilies " . ($startsmilies+1) . " to " . min(($startsmilies+30),($smiliescount+0)) . " of " . $smiliescount;
// display a link to the next page, if needed
if ($startsmilies<$smiliescount-30) {
$linkstartsmilies=$startsmilies+30;
$smilieslink .= " / <a href=\"index.php?action=showsmilies&startsmilies=$linkstartsmilies\">Next</a>";
}
eval("echo dovars(\"".gettemplate("smilies")."\");"); // added line to "smilies" to show link to previous and/or next page
}
In the "smilies" template you have to add the "$smilieslink" variable wherever you want your Previous/Next links to appear. I put mine after the table closes but before the centering closes:
$smiliebits
</table>
$smilieslink
</center>
Peter E. Humphries
[Edited by phumphries on 07-26-2000 at 01:14 PM]