m0tSiE
asked on
Pagination Error Message:
Hi,
I am having problems with pagination that I have setup using this tutorial,
http://www.goodphptutorials.com/article/show/simple-php-mysql-pagination/2
I "think" i've added it to my page correctly, however when I try my search I get this error message:
Fatal error: Call to a member function getLimitSql() on a non-object in /home2/cawsearc/public_htm l/svr2008/ caws4.php on line 351
I've checked line 351 and it is my query,
$result = "SELECT * FROM caws WHERE name LIKE '$letter%' ORDER BY name" . $pagination->getLimitSql() ;
Can anyone see what i've done wrong?
Thanks,
Paul.
I am having problems with pagination that I have setup using this tutorial,
http://www.goodphptutorials.com/article/show/simple-php-mysql-pagination/2
I "think" i've added it to my page correctly, however when I try my search I get this error message:
Fatal error: Call to a member function getLimitSql() on a non-object in /home2/cawsearc/public_htm
I've checked line 351 and it is my query,
$result = "SELECT * FROM caws WHERE name LIKE '$letter%' ORDER BY name" . $pagination->getLimitSql()
Can anyone see what i've done wrong?
Thanks,
Paul.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Smackdown vs RAW 2008 CAWS - CAWSearch.com</title>
<link rel="stylesheet" type="text/css" href="http://cawsearch.com/css/hoverbox.css" />
<link rel="stylesheet" type="text/css" href="http://cawsearch.com/css/ie_fixes.css" />
<style>
body{
font-family: Arial;
font-size: 12px;
color: #000000;
}
.results-header{
background: #F4F4F4 url(http://cawsearch.com/images/site/header-blue.jpg);
font-family: Arial;
font-weight: bold;
font-size: 12px;
color: #FFFFFF;
padding: 5px;
border-right-style: dotted;
border-right-width: 1px;
border-bottom-style: dotted;
border-bottom-width: 1px;
border-top-style: dotted;
border-top-width: 1px;
}
.results-header-left{
background: #F4F4F4 url(http://cawsearch.com/images/site/header-blue.jpg);
font-family: Arial;
font-weight: bold;
font-size: 12px;
color: #FFFFFF;
padding: 5px;
border-style: dotted;
border-width: 1px;
}
.results-show a:active,
.results-show a:visited,
.results-show a:link{
color: #407CBF;
}
.results-show{
font-family: Arial;
font-size: 12px;
color: #000000;
padding: 5px;
border-color: #E0DFE3;
border-right-style: dotted;
border-right-width: 1px;
border-bottom-style: dotted;
border-bottom-width: 1px;
}
.results-show-multi{
font-family: Arial;
font-size: 12px;
color: #000000;
padding: 5px;
border-color: #E0DFE3;
border-right-style: dotted;
border-right-width: 1px;
border-bottom-style: dotted;
border-bottom-width: 1px;
border-left-style: dotted;
border-left-width: 1px;
}
.results-show-left{
font-family: Arial;
font-size: 12px;
color: #000000;
padding: 5px;
border-color: #E0DFE3;
border-left-style: dotted;
border-left-width: 1px;
border-bottom-style: dotted;
border-bottom-width: 1px;
border-right-style: dotted;
border-right-width: 1px;
}
.results-footer{
font-family: Arial;
font-size: 10px;
color: #000000;
padding: 5px;
}
.test{
font-family: Arial;
font-size: 10px;
color: #000000;
padding: 5px;
}
.navigation{
font-family: Arial;
font-size: 12px;
color: #000000;
}
</style>
</head>
<body link="#407CBF" vlink="#407CBF" alink="#407CBF">
<center>
<a href="http://cawsearch.com/"><img border="0" src="http://cawsearch.com/images/site/CAWSearch.png"></a>
<br>
<form method="post" action="http://cawsearch.com/svr2008/search.php">
<input type="text" name="search" size=25 maxlength=25>
<select onchange="this.form.action=this.options[this.selectedIndex].value">
<option value="http://cawsearch.com/svr2008/search.php">Smackdown vs RAW 2008</option>
<option value="http://cawsearch.com/dor2/caws.php">Day Of Reckoning 2</option>
</select>
<input type="Submit" name="Submit" value="Search">
</form>
<a href="http://cawsearch.com/games.php">Browse Games</a> - <a href="http://cawsearch.com/submit.php">Submit Your Creation</a> - <a href="http://forums.smacktalks.org/">Community</a><br>
<br><br>
<table border="0" width="800" cellpadding="0">
<tr>
<td width="240" align="right"><img border="0" src="http://cawsearch.com/images/site/svr2008.png"></td>
<td width="560" align="center" class="navigation">Browse: <a href="caws.php">CAWS</a> | <a href="movesets.php">Movesets</a> | <a href="belts.php">Belts</a> | <a href="entrances.php">Entrances</a> | <a href="attributes.php">Attributes</a> | <a href="#">Submit Your Creation</a><br><br>
Currently Viewing: CAWS (<?php if (isset($_GET['letter'])) echo $_GET['letter']; else echo "All";?>)<br><br>
<a href="caws.php">All</a> | <a href="?letter=0">0</a> <a href="?letter=1">1</a> <a href="?letter=2">2</a> <a href="?letter=3">3</a> <a href="?letter=4">4</a> <a href="?letter=5">5</a> <a href="?letter=6">6</a> <a href="?letter=7">7</a> <a href="?letter=8">8</a> <a href="?letter=9">9</a> | <a href="?letter=A">A</a> <a href="?letter=B">B</a> <a href="?letter=C">C</a> <a href="?letter=D">D</a> <a href="?letter=E">E</a> <a href="?letter=F">F</a> <a href="?letter=G">G</a> <a href="?letter=H">H</a> <a href="?letter=I">I</a> <a href="?letter=J">J</a> <a href="?letter=K">K</a> <a href="?letter=L">L</a> <a href="?letter=M">M</a> <a href="?letter=N">N</a> <a href="?letter=O">O</a> <a href="?letter=P">P</a> <a href="?letter=Q">Q</a> <a href="?letter=R">R</a> <a href="?letter=S">S</a> <a href="?letter=T">T</a> <a href="?letter=U">U</a> <a href="?letter=V">V</a> <a href="?letter=W">W</a> <a href="?letter=X">X</a> <a href="?letter=Y">Y</a> <a href="?letter=Z">Z</a></td>
</tr>
</table><br>
<table border="0" cellspacing="0" cellpadding="0" class="test">
<tr>
<td class="results-header-left" width="20"> </td>
<td class="results-header" width="180">Name</td>
<td class="results-header" width="130">Attire</td>
<td class="results-header" width="130">Creator</td>
<td class="results-header" width="40">Rating</td>
<td class="results-header" width="50">Preview</td>
<td class="results-header" width="50">Attributes</td>
<td class="results-header" width="50">Entrance</td>
<td class="results-header" width="50">Movesets</td>
</tr>
<?php
//connect to mysql
mysql_connect("localhost","","");
mysql_select_db("");
$letter=mysql_real_escape_string($_GET["letter"]);
class Pagination
{
/**
* Current Page
*
* @var integer
*/
var $page;
/**
* Size of the records per page
*
* @var integer
*/
var $size;
/**
* Total records
*
* @var integer
*/
var $total_records;
/**
* Link used to build navigation
*
* @var string
*/
var $link;
/**
* Class Constructor
*
* @param integer $page
* @param integer $size
* @param integer $total_records
*/
function Pagination($page = null, $size = null, $total_records = null)
{
$this->page = $page;
$this->size = $size;
$this->total_records = $total_records;
}
/**
* Set's the current page
*
* @param unknown_type $page
*/
function setPage($page)
{
$this->page = 0+$page;
}
/**
* Set's the records per page
*
* @param integer $size
*/
function setSize($size)
{
$this->size = 0+$size;
}
/**
* Set's total records
*
* @param integer $total
*/
function setTotalRecords($total)
{
$this->total_records = 0+$total;
}
/**
* Sets the link url for navigation pages
*
* @param string $url
*/
function setLink($url)
{
$this->link = $url;
}
/**
* Returns the LIMIT sql statement
*
* @return string
*/
function getLimitSql()
{
$sql = "LIMIT " . $this->getLimit();
return $sql;
}
/**
* Get the LIMIT statment
*
* @return string
*/
function getLimit()
{
if ($this->total_records == 0)
{
$lastpage = 0;
}
else
{
$lastpage = ceil($this->total_records/$this->size);
}
$page = $this->page;
if ($this->page < 1)
{
$page = 1;
}
else if ($this->page > $lastpage && $lastpage > 0)
{
$page = $lastpage;
}
else
{
$page = $this->page;
}
$sql = ($page - 1) * $this->size . "," . $this->size;
return $sql;
}
/**
* Creates page navigation links
*
* @return string
*/
function create_links()
{
$totalItems = $this->total_records;
$perPage = $this->size;
$currentPage = $this->page;
$link = $this->link;
$totalPages = floor($totalItems / $perPage);
$totalPages += ($totalItems % $perPage != 0) ? 1 : 0;
if ($totalPages < 1 || $totalPages == 1){
return null;
}
$output = null;
//$output = '<span id="total_page">Page (' . $currentPage . '/' . $totalPages . ')</span> ';
$loopStart = 1;
$loopEnd = $totalPages;
if ($totalPages > 5)
{
if ($currentPage <= 3)
{
$loopStart = 1;
$loopEnd = 5;
}
else if ($currentPage >= $totalPages - 2)
{
$loopStart = $totalPages - 4;
$loopEnd = $totalPages;
}
else
{
$loopStart = $currentPage - 2;
$loopEnd = $currentPage + 2;
}
}
if ($loopStart != 1){
$output .= sprintf('<li class="disabledpage"><a href="' . $link . '">«</a></li>', '1');
}
if ($currentPage > 1){
$output .= sprintf('<li class="nextpage"><a href="' . $link . '">Previous</a></li>', $currentPage - 1);
}
for ($i = $loopStart; $i <= $loopEnd; $i++)
{
if ($i == $currentPage){
$output .= '<li class="currentpage">' . $i . '</li> ';
} else {
$output .= sprintf('<li><a href="' . $link . '">', $i) . $i . '</a></li> ';
}
}
if ($currentPage < $totalPages){
$output .= sprintf('<li class="nextpage"><a href="' . $link . '">Next</a></li>', $currentPage + 1);
}
if ($loopEnd != $totalPages){
$output .= sprintf('<li class="nextpage"><a href="' . $link . '">»</a></li>', $totalPages);
}
return '<div class="pagination"><ul>' . $output . '</ul></div>';
}
}
// SQL statement to get records from table
$result = "SELECT * FROM caws WHERE name LIKE '$letter%' ORDER BY name" . $pagination->getLimitSql();
$page = 1;
// how many records per page
$size = 1;
// we get the current page from $_GET
if (isset($_GET['page'])){
$page = (int) $_GET['page'];
}
// create the pagination class
$pagination = new Pagination();
$pagination->setLink("list.php?page=%s");
$pagination->setPage($page);
$pagination->setSize($size);
$pagination->setTotalRecords($total_records);
$arr_data = array();
echo mysql_error();
while ($row = mysql_fetch_assoc($result))
{
if (!isset($arr_data[$row["name"]]))
{
$arr_data[$row["name"]] = array();
}
$arr_data[$row["name"]][] = $row;
}
foreach ( $arr_data as $name => $rows )
{
if (sizeof($rows) == 1)
{ // only 1 details row, print all on 1 row
$row = $rows[0];
$detail_row = 1;
$total_value=$row['total_value'];
$total_votes=$row['total_votes'];
$rating = ($total_votes>0)?round($total_value / $total_votes,$decimals):0;
print "
<tr>
<td class=results-show-left><img src='http://cawsearch.com/images/icons/{$row["console"]}.png'></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/view_caw.php?idx={$row["id"]}'>{$row["name"]}</a></td>
<td class=results-show>{$row["attire"]}</td>
<td class=results-show><a href='http://cawsearch.com/svr2008/creator.php?c={$row["creator"]}'>{$row["creator"]}</a></td>
<td class=results-show>$rating/10</td>
<td class=hoverbox><li><a href=#>Roll Over<img src=http://cawsearch.com{$row["image"]} class=preview /></a></li></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/attributes.php?letter={$row["name"]}'>Click Here</a></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/entrances.php?letter={$row["name"]}'>Click Here</a></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/movesets.php?letter={$row["name"]}'>Click Here</a></td>
</tr>";
}
else // if (sizeof($rows) == 1)
{
// print the name's row
print "
<tr>
<td class=results-show-left> </td>
<td colspan=9 class=results-show-multi>
<a href='#' onclick=\"document.getElementById('row{$row["id"]}').style.display=='none' ? document.getElementById('row{$row["id"]}').style.display='' : document.getElementById('row{$row["id"]}').style.display = 'none';return false\">
<b>{$name}</b> <i>- (Multiple Results)</i>
</a>
</td>
</tr>
";
print "
<tr><td colspan=9><div id='row{$row["id"]}' style='display:none;'><table border='0' cellspacing='0' cellpadding='0' class='test'>
<tr>
<td class='results-header-left' width='20'> </td>
<td class='results-header' width='180'>Name</td>
<td class='results-header' width='130'>Attire</td>
<td class='results-header' width='130'>Creator</td>
<td class='results-header' width='40'>Rating</td>
<td class='results-header' width='50'>Preview</td>
<td class='results-header' width='50'>Attributes</td>
<td class='results-header' width='50'>Entrance</td>
<td class='results-header' width='50'>Movesets</td>
</tr>";
$detail_row = 0;
foreach ( $rows as $row )
{
$detail_row++;
$total_value2=$row['total_value'];
$total_votes2=$row['total_votes'];
$rating2 = ($total_votes2>0)?round($total_value2 / $total_votes2,$decimals):0;
print "
<tr>
<td class=results-show-left><img src='http://cawsearch.com/images/icons/{$row["console"]}.png'></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/view_caw.php?idx={$row["id"]}'>{$row["name"]}</a> ($detail_row)</td>
<td class=results-show>{$row["attire"]}</td>
<td class=results-show><a href='http://http://cawsearch.com/svr2008/creator.php?c={$row["creator"]}'>{$row["creator"]}</a></td>
<td class=results-show>$rating2/10</td>
<td class=hoverbox><li><a href=#>Roll Over<img src=http://cawsearch.com{$row["image"]} class=preview /></a></li></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/attributes.php?letter={$row["name"]}'>Click Here</a></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/entrances.php?letter={$row["name"]}'>Click Here</a></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/movesets.php?letter={$row["name"]}'>Click Here</a></td>
</tr>";
} // foreach ( $rows as $row )
print "
</table></div></td></tr>
";
} // else if (sizeof($rows) == 1)
} // foreach ( $arr_data as $name => $rows )
?>
</table>
<br><br><font size="1">CAWSearch 1.0.1</font>
</center>
</body>
</html>
ASKER
Thanks, I've just updated it but it shows this new error.
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home2/cawsearc/public_htm l/svr2008/ caws5.php on line 376
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home2/cawsearc/public_htm
You were also missing a mysql_query ..... try the below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Smackdown vs RAW 2008 CAWS - CAWSearch.com</title>
<link rel="stylesheet" type="text/css" href="http://cawsearch.com/css/hoverbox.css" />
<link rel="stylesheet" type="text/css" href="http://cawsearch.com/css/ie_fixes.css" />
<style>
body{
font-family: Arial;
font-size: 12px;
color: #000000;
}
.results-header{
background: #F4F4F4 url(http://cawsearch.com/images/site/header-blue.jpg);
font-family: Arial;
font-weight: bold;
font-size: 12px;
color: #FFFFFF;
padding: 5px;
border-right-style: dotted;
border-right-width: 1px;
border-bottom-style: dotted;
border-bottom-width: 1px;
border-top-style: dotted;
border-top-width: 1px;
}
.results-header-left{
background: #F4F4F4 url(http://cawsearch.com/images/site/header-blue.jpg);
font-family: Arial;
font-weight: bold;
font-size: 12px;
color: #FFFFFF;
padding: 5px;
border-style: dotted;
border-width: 1px;
}
.results-show a:active,
.results-show a:visited,
.results-show a:link{
color: #407CBF;
}
.results-show{
font-family: Arial;
font-size: 12px;
color: #000000;
padding: 5px;
border-color: #E0DFE3;
border-right-style: dotted;
border-right-width: 1px;
border-bottom-style: dotted;
border-bottom-width: 1px;
}
.results-show-multi{
font-family: Arial;
font-size: 12px;
color: #000000;
padding: 5px;
border-color: #E0DFE3;
border-right-style: dotted;
border-right-width: 1px;
border-bottom-style: dotted;
border-bottom-width: 1px;
border-left-style: dotted;
border-left-width: 1px;
}
.results-show-left{
font-family: Arial;
font-size: 12px;
color: #000000;
padding: 5px;
border-color: #E0DFE3;
border-left-style: dotted;
border-left-width: 1px;
border-bottom-style: dotted;
border-bottom-width: 1px;
border-right-style: dotted;
border-right-width: 1px;
}
.results-footer{
font-family: Arial;
font-size: 10px;
color: #000000;
padding: 5px;
}
.test{
font-family: Arial;
font-size: 10px;
color: #000000;
padding: 5px;
}
.navigation{
font-family: Arial;
font-size: 12px;
color: #000000;
}
</style>
</head>
<body link="#407CBF" vlink="#407CBF" alink="#407CBF">
<center>
<a href="http://cawsearch.com/"><img border="0" src="http://cawsearch.com/images/site/CAWSearch.png"></a>
<br>
<form method="post" action="http://cawsearch.com/svr2008/search.php">
<input type="text" name="search" size=25 maxlength=25>
<select onchange="this.form.action=this.options[this.selectedIndex].value">
<option value="http://cawsearch.com/svr2008/search.php">Smackdown vs RAW 2008</option>
<option value="http://cawsearch.com/dor2/caws.php">Day Of Reckoning 2</option>
</select>
<input type="Submit" name="Submit" value="Search">
</form>
<a href="http://cawsearch.com/games.php">Browse Games</a> - <a href="http://cawsearch.com/submit.php">Submit Your Creation</a> - <a href="http://forums.smacktalks.org/">Community</a><br>
<br><br>
<table border="0" width="800" cellpadding="0">
<tr>
<td width="240" align="right"><img border="0" src="http://cawsearch.com/images/site/svr2008.png"></td>
<td width="560" align="center" class="navigation">Browse: <a href="caws.php">CAWS</a> | <a href="movesets.php">Movesets</a> | <a href="belts.php">Belts</a> | <a href="entrances.php">Entrances</a> | <a href="attributes.php">Attributes</a> | <a href="#">Submit Your Creation</a><br><br>
Currently Viewing: CAWS (<?php if (isset($_GET['letter'])) echo $_GET['letter']; else echo "All";?>)<br><br>
<a href="caws.php">All</a> | <a href="?letter=0">0</a> <a href="?letter=1">1</a> <a href="?letter=2">2</a> <a href="?letter=3">3</a> <a href="?letter=4">4</a> <a href="?letter=5">5</a> <a href="?letter=6">6</a> <a href="?letter=7">7</a> <a href="?letter=8">8</a> <a href="?letter=9">9</a> | <a href="?letter=A">A</a> <a href="?letter=B">B</a> <a href="?letter=C">C</a> <a href="?letter=D">D</a> <a href="?letter=E">E</a> <a href="?letter=F">F</a> <a href="?letter=G">G</a> <a href="?letter=H">H</a> <a href="?letter=I">I</a> <a href="?letter=J">J</a> <a href="?letter=K">K</a> <a href="?letter=L">L</a> <a href="?letter=M">M</a> <a href="?letter=N">N</a> <a href="?letter=O">O</a> <a href="?letter=P">P</a> <a href="?letter=Q">Q</a> <a href="?letter=R">R</a> <a href="?letter=S">S</a> <a href="?letter=T">T</a> <a href="?letter=U">U</a> <a href="?letter=V">V</a> <a href="?letter=W">W</a> <a href="?letter=X">X</a> <a href="?letter=Y">Y</a> <a href="?letter=Z">Z</a></td>
</tr>
</table><br>
<table border="0" cellspacing="0" cellpadding="0" class="test">
<tr>
<td class="results-header-left" width="20"> </td>
<td class="results-header" width="180">Name</td>
<td class="results-header" width="130">Attire</td>
<td class="results-header" width="130">Creator</td>
<td class="results-header" width="40">Rating</td>
<td class="results-header" width="50">Preview</td>
<td class="results-header" width="50">Attributes</td>
<td class="results-header" width="50">Entrance</td>
<td class="results-header" width="50">Movesets</td>
</tr>
<?php
//connect to mysql
mysql_connect("localhost","","");
mysql_select_db("");
$letter=mysql_real_escape_string($_GET["letter"]);
class Pagination
{
/**
* Current Page
*
* @var integer
*/
var $page;
/**
* Size of the records per page
*
* @var integer
*/
var $size;
/**
* Total records
*
* @var integer
*/
var $total_records;
/**
* Link used to build navigation
*
* @var string
*/
var $link;
/**
* Class Constructor
*
* @param integer $page
* @param integer $size
* @param integer $total_records
*/
function Pagination($page = null, $size = null, $total_records = null)
{
$this->page = $page;
$this->size = $size;
$this->total_records = $total_records;
}
/**
* Set's the current page
*
* @param unknown_type $page
*/
function setPage($page)
{
$this->page = 0+$page;
}
/**
* Set's the records per page
*
* @param integer $size
*/
function setSize($size)
{
$this->size = 0+$size;
}
/**
* Set's total records
*
* @param integer $total
*/
function setTotalRecords($total)
{
$this->total_records = 0+$total;
}
/**
* Sets the link url for navigation pages
*
* @param string $url
*/
function setLink($url)
{
$this->link = $url;
}
/**
* Returns the LIMIT sql statement
*
* @return string
*/
function getLimitSql()
{
$sql = "LIMIT " . $this->getLimit();
return $sql;
}
/**
* Get the LIMIT statment
*
* @return string
*/
function getLimit()
{
if ($this->total_records == 0)
{
$lastpage = 0;
}
else
{
$lastpage = ceil($this->total_records/$this->size);
}
$page = $this->page;
if ($this->page < 1)
{
$page = 1;
}
else if ($this->page > $lastpage && $lastpage > 0)
{
$page = $lastpage;
}
else
{
$page = $this->page;
}
$sql = ($page - 1) * $this->size . "," . $this->size;
return $sql;
}
/**
* Creates page navigation links
*
* @return string
*/
function create_links()
{
$totalItems = $this->total_records;
$perPage = $this->size;
$currentPage = $this->page;
$link = $this->link;
$totalPages = floor($totalItems / $perPage);
$totalPages += ($totalItems % $perPage != 0) ? 1 : 0;
if ($totalPages < 1 || $totalPages == 1){
return null;
}
$output = null;
//$output = '<span id="total_page">Page (' . $currentPage . '/' . $totalPages . ')</span> ';
$loopStart = 1;
$loopEnd = $totalPages;
if ($totalPages > 5)
{
if ($currentPage <= 3)
{
$loopStart = 1;
$loopEnd = 5;
}
else if ($currentPage >= $totalPages - 2)
{
$loopStart = $totalPages - 4;
$loopEnd = $totalPages;
}
else
{
$loopStart = $currentPage - 2;
$loopEnd = $currentPage + 2;
}
}
if ($loopStart != 1){
$output .= sprintf('<li class="disabledpage"><a href="' . $link . '">«</a></li>', '1');
}
if ($currentPage > 1){
$output .= sprintf('<li class="nextpage"><a href="' . $link . '">Previous</a></li>', $currentPage - 1);
}
for ($i = $loopStart; $i <= $loopEnd; $i++)
{
if ($i == $currentPage){
$output .= '<li class="currentpage">' . $i . '</li> ';
} else {
$output .= sprintf('<li><a href="' . $link . '">', $i) . $i . '</a></li> ';
}
}
if ($currentPage < $totalPages){
$output .= sprintf('<li class="nextpage"><a href="' . $link . '">Next</a></li>', $currentPage + 1);
}
if ($loopEnd != $totalPages){
$output .= sprintf('<li class="nextpage"><a href="' . $link . '">»</a></li>', $totalPages);
}
return '<div class="pagination"><ul>' . $output . '</ul></div>';
}
}
$page = 1;
// how many records per page
$size = 1;
// we get the current page from $_GET
if (isset($_GET['page'])){
$page = (int) $_GET['page'];
}
// create the pagination class
$pagination = new Pagination();
$pagination->setLink("list.php?page=%s");
$pagination->setPage($page);
$pagination->setSize($size);
$pagination->setTotalRecords($total_records);
// SQL statement to get records from table
$SQL = "SELECT * FROM caws WHERE name LIKE '$letter%' ORDER BY name" . $pagination->getLimitSql();
$result = mysql_query($SQL);
$arr_data = array();
echo mysql_error();
while ($row = mysql_fetch_assoc($result))
{
if (!isset($arr_data[$row["name"]]))
{
$arr_data[$row["name"]] = array();
}
$arr_data[$row["name"]][] = $row;
}
foreach ( $arr_data as $name => $rows )
{
if (sizeof($rows) == 1)
{ // only 1 details row, print all on 1 row
$row = $rows[0];
$detail_row = 1;
$total_value=$row['total_value'];
$total_votes=$row['total_votes'];
$rating = ($total_votes>0)?round($total_value / $total_votes,$decimals):0;
print "
<tr>
<td class=results-show-left><img src='http://cawsearch.com/images/icons/{$row["console"]}.png'></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/view_caw.php?idx={$row["id"]}'>{$row["name"]}</a></td>
<td class=results-show>{$row["attire"]}</td>
<td class=results-show><a href='http://cawsearch.com/svr2008/creator.php?c={$row["creator"]}'>{$row["creator"]}</a></td>
<td class=results-show>$rating/10</td>
<td class=hoverbox><li><a href=#>Roll Over<img src=http://cawsearch.com{$row["image"]} class=preview /></a></li></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/attributes.php?letter={$row["name"]}'>Click Here</a></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/entrances.php?letter={$row["name"]}'>Click Here</a></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/movesets.php?letter={$row["name"]}'>Click Here</a></td>
</tr>";
}
else // if (sizeof($rows) == 1)
{
// print the name's row
print "
<tr>
<td class=results-show-left> </td>
<td colspan=9 class=results-show-multi>
<a href='#' onclick=\"document.getElementById('row{$row["id"]}').style.display=='none' ? document.getElementById('row{$row["id"]}').style.display='' : document.getElementById('row{$row["id"]}').style.display = 'none';return false\">
<b>{$name}</b> <i>- (Multiple Results)</i>
</a>
</td>
</tr>
";
print "
<tr><td colspan=9><div id='row{$row["id"]}' style='display:none;'><table border='0' cellspacing='0' cellpadding='0' class='test'>
<tr>
<td class='results-header-left' width='20'> </td>
<td class='results-header' width='180'>Name</td>
<td class='results-header' width='130'>Attire</td>
<td class='results-header' width='130'>Creator</td>
<td class='results-header' width='40'>Rating</td>
<td class='results-header' width='50'>Preview</td>
<td class='results-header' width='50'>Attributes</td>
<td class='results-header' width='50'>Entrance</td>
<td class='results-header' width='50'>Movesets</td>
</tr>";
$detail_row = 0;
foreach ( $rows as $row )
{
$detail_row++;
$total_value2=$row['total_value'];
$total_votes2=$row['total_votes'];
$rating2 = ($total_votes2>0)?round($total_value2 / $total_votes2,$decimals):0;
print "
<tr>
<td class=results-show-left><img src='http://cawsearch.com/images/icons/{$row["console"]}.png'></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/view_caw.php?idx={$row["id"]}'>{$row["name"]}</a> ($detail_row)</td>
<td class=results-show>{$row["attire"]}</td>
<td class=results-show><a href='http://http://cawsearch.com/svr2008/creator.php?c={$row["creator"]}'>{$row["creator"]}</a></td>
<td class=results-show>$rating2/10</td>
<td class=hoverbox><li><a href=#>Roll Over<img src=http://cawsearch.com{$row["image"]} class=preview /></a></li></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/attributes.php?letter={$row["name"]}'>Click Here</a></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/entrances.php?letter={$row["name"]}'>Click Here</a></td>
<td class=results-show><a href='http://cawsearch.com/svr2008/movesets.php?letter={$row["name"]}'>Click Here</a></td>
</tr>";
} // foreach ( $rows as $row )
print "
</table></div></td></tr>
";
} // else if (sizeof($rows) == 1)
} // foreach ( $arr_data as $name => $rows )
?>
</table>
<br><br><font size="1">CAWSearch 1.0.1</font>
</center>
</body>
</html>
ASKER
Thanks, i've updated it but it's now showing.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0,1' at line 1
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home2/cawsearc/public_htm l/svr2008/ caws5.php on line 378
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0,1' at line 1
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home2/cawsearc/public_htm
m0tSiE do a print $SQL right after
$SQL = "SELECT * FROM caws WHERE name LIKE '$letter%' ORDER BY name" . $pagination->getLimitSql() ;
and tell me the result
$SQL = "SELECT * FROM caws WHERE name LIKE '$letter%' ORDER BY name" . $pagination->getLimitSql()
and tell me the result
ASKER
So just add print $SQL on the line after my query?
It gives me the error:
Parse error: syntax error, unexpected T_VARIABLE in /home2/cawsearc/public_htm l/svr2008/ caws5.php on line 374
However if I take out all the table html and just use print $SQL it shows:
SELECT * FROM caws WHERE name LIKE '%' ORDER BY nameLIMIT 0,1
Is that what you wanted?
It gives me the error:
Parse error: syntax error, unexpected T_VARIABLE in /home2/cawsearc/public_htm
However if I take out all the table html and just use print $SQL it shows:
SELECT * FROM caws WHERE name LIKE '%' ORDER BY nameLIMIT 0,1
Is that what you wanted?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that's working great :D
Would you mind showing me where to add the navigation code for the pagination? As I'm not sure where to add it to my code.
$navigation = $pagination->create_links( );
echo $navigation; // will draw our page navigation
Would you mind showing me where to add the navigation code for the pagination? As I'm not sure where to add it to my code.
$navigation = $pagination->create_links(
echo $navigation; // will draw our page navigation
I suppose adding
<tr>
<td colspan="9" align="center" height="35" valign="middle">
<? $navigation = $pagination->create_links( );echo $navigation; // will draw our page navigation ?>
</td>
</tr>
before the closing </table> tag will do the trick
<tr>
<td colspan="9" align="center" height="35" valign="middle">
<? $navigation = $pagination->create_links(
</td>
</tr>
before the closing </table> tag will do the trick
ASKER
Worked great, many thanks! :D
Try this
Open in new window