Forum Moderators: open
And what are the solution to optimize the codes to make it load faster?
Are the codes below can cause slow loading to the server?
<?php
session_start();
###################
# Display big photos #
###################
include "opendb.php";####################################################
# P A G I N G start #
####################################################
###################
# Start Browse by rows #
###################
// how many rows to show per page
$rowsPerPage = isset($_GET['row'])? $_GET['row'] : 25;
$rowsPerPage = (int)($rowsPerPage);
//pag nag submit ang user
//lalagay niya sa session tapos assign niya s $total_row2
if(isset($_GET['row'])) {
$_SESSION['total_row'] = (int)($_GET['row']);
}
//kapag yong total_row ay hinde blanko
//assign niya ang value din don sa $rowsPerPage. Ibig sabihin na pindot na o may laman na.
if(isset($_SESSION['total_row'])) {
$rowsPerPage=$_SESSION['total_row'];
$xpose_Rec = $_SESSION['total_row'];
}
###################
# End Browse by rows #
###################
###################
# Start FILTER #
###################
###################
# End FILTER #
###################
#$rowsPerPage = 25;
$xpose_Rec = $rowsPerPage;
$i = 1;
// by default we show first page
$pageNum = 1;
$cnt=1;
echo "rowsPerPage: " . $rowsPerPage;
echo " xpose_Rec: " . $xpose_Rec;
//row per page
#if( $_GET['rowsPerPage'] )
#$rowsPerPage = (int)($_GET['rowsPerPage']);
// if $_GET['page'] very important baby
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$ctr=0;
$query = "SELECT * FROM cclp_players LIMIT $offset, $xpose_Rec";
$result = mysql_query($query) or die('Error, query failed');
// print the student info in table
echo "<div align='center'>";
echo "<p>";
//get default directories
//www.golem.cc/dev/tmt/images/teams
//echo ('<a href="img_info.php?current_file='.$current_file.'"><img src="'.$current_img.'" border="1"><h1> </h1></a>');
$images_dir = 'http://' . $_SERVER['HTTP_HOST'] . '/dev/tmt/images/teams/';
$images_dir2 = 'http://' . $_SERVER['HTTP_HOST'] . '/dev/tmt/images/';
$images_pic2 = $images_dir2 . "golemavatar.gif";
$cnt2=0;
echo "<table border='0' width='700px' cellspacing='0' cellpadding='0' bgcolor=''>";
while(list($id, $lname, $fname, $birthday, $email, $hphone, $wphone, $address, $teamid, $position, $number, $info, $taglia, $sport1, $sport2, $sport3, $citta, $likedin, $photo) = mysql_fetch_array($result)) {
$images_pic = $images_dir . $photo;
if($cnt2==5) {
echo "<tr>";
}
echo "<td width='20px' valign='top'>";
//display the image
//<a href="'.$images_pic[""].'" onmouseover="alert("'.$images_pic["what_ever"].'")>
if($photo!=""){
echo ('
<a href="'.$images_pic[""].'">
<img src="'.$images_pic.'" alt="testing" width="118" height="118" border="2"/></a>');
}
//display temporary image if $photo is empty.
if($photo==""){
echo ('<img src="'.$images_pic2.'" width="118" height="118" border="2"/>');
}
echo "<b><br>$lname</b>";
echo "<br>$hphone";
echo "<br>$goals";
echo "<br>$yellowcards";
echo "<br>$redcards";
echo "<br>$position";
echo "<br>$number";
echo "<br>$$info";
echo "<br>$likedin";
echo "<br>$birthday";
echo "</td>";
$cnt2++;
if($cnt2==5) {
echo "</tr>";
$cnt2=0;
}
}
echo "</table>";
echo "</div>";
echo "</p>";
echo "<br>";
#######################
# Displaying previous and next links #
#######################
// how many rows we have in database
$query = "SELECT COUNT(id) AS numrows FROM cclp_players";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numRows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numRows/$xpose_Rec);
$self = $_SERVER['PHP_SELF'];
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
#<a href="forumdisplay.php?f=34&daysprune=-1&order=desc&sort=views" rel="nofollow">Views</a>
#$next = " <a href=\"$self?page=$page\">[Next]</a> ";
#http://www.golem.cc/big-list2.php?row=50&B1=Submit
#<a href="forumdisplay.php?f=34&daysprune=-1&order=desc&sort=views" rel="nofollow">
$next = " <a href=\"$self?page=$page&rowsPerPage=$rowsPerPage?xpose_Rec=$rowsPerPage\" rel=\"nofollow\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}
// print the page navigation link
echo "<center>";
echo $first . $prev . " Page <strong>$pageNum</strong> of <strong>$maxPage</strong> " . $next . $last;
echo "</center>";
####################################################
#P A G I N G stop #
####################################################
echo "<br>";
?>
Thank you very much in advance.