[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Pagination, discount same name results from pagination?

Posted on 2008-01-27
13
Medium Priority
?
315 Views
Last Modified: 2013-12-12
HI,

I have yet another problem with my pagination :(

In my database I currently have 4 entries and two of these have the same name, therefore rather than show a list of results with the same name I have them in an expandable <div>, therefore in my search results it only shows as 1 row. The problem I have is that the pagination counts these rows that are hidden in the <div>, because of this if I set the pagination to show 50 results and 49 results have the same name and are hidden with the expandable div, then my serach page only looks like it shows 2 results.

Is there a way I can set the pagination to not count results with the same name against the pagination?

Example:
As I only have 4 results in my table (Chris Benoit, Chris Jericho, Chris Jericho & Kurt Angle), i've set the pagination to show 3 results per page. However two of these results have the same name and are shown in a expandable div.

http://cawsearch.com/svr2008/search.php

As you can see on the link above the pagination counts the second Jericho with the same name as the third result in the pagination, can I set it to ignore the results with the same name? So that it would return...

Chris Benoit
Chris Jericho - (Multiple Results)
Kurt Angle

So it shows 4 results counting the 2 in the <div>, even though the pagination is set to 3 results per page.

Thanks,
Paul.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<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;
}
.pagination{
padding: 2px;
}
 
.pagination ul{
margin: 0;
padding: 0;
text-align: left; /*Set to "right" to right align pagination interface*/
font-size: 12px;
}
 
.pagination li{
list-style-type: none;
display: inline;
padding-bottom: 1px;
}
 
.pagination a, .pagination a:visited{
padding: 0 5px;
border: 1px solid #9aafe5;
text-decoration: none; 
color: #2e6ab1;
}
 
.pagination a:hover, .pagination a:active{
border: 1px solid #2b66a5;
color: #000;
background-color: #a0bedf;
}
 
.pagination a.currentpage{
background-color: #2e6ab1;
color: #FFF !important;
border-color: #2b66a5;
font-weight: bold;
cursor: default;
}
 
.pagination a.disablelink, .pagination a.disablelink:hover{
background-color: white;
cursor: default;
color: #929292;
border-color: #929292;
font-weight: normal !important;
}
 
.pagination a.prevnext{
font-weight: bold;
}
</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="caws.php?letter=0">0</a> <a href="caws.php?letter=1">1</a> <a href="caws.php?letter=2">2</a> <a href="caws.php?letter=3">3</a> <a href="caws.php?letter=4">4</a> <a href="caws.php?letter=5">5</a> <a href="caws.php?letter=6">6</a> <a href="caws.php?letter=7">7</a> <a href="caws.php?letter=8">8</a> <a href="caws.php?letter=9">9</a> | <a href="caws.php?letter=A">A</a> <a href="caws.php?letter=B">B</a> <a href="caws.php?letter=C">C</a> <a href="caws.php?letter=D">D</a> <a href="caws.php?letter=E">E</a> <a href="caws.php?letter=F">F</a> <a href="caws.php?letter=G">G</a> <a href="caws.php?letter=H">H</a> <a href="caws.php?letter=I">I</a> <a href="caws.php?letter=J">J</a> <a href="caws.php?letter=K">K</a> <a href="caws.php?letter=L">L</a> <a href="caws.php?letter=M">M</a> <a href="caws.php?letter=N">N</a> <a href="caws.php?letter=O">O</a> <a href="caws.php?letter=P">P</a> <a href="caws.php?letter=Q">Q</a> <a href="caws.php?letter=R">R</a> <a href="caws.php?letter=S">S</a> <a href="caws.php?letter=T">T</a> <a href="caws.php?letter=U">U</a> <a href="caws.php?letter=V">V</a> <a href="caws.php?letter=W">W</a> <a href="caws.php?letter=X">X</a> <a href="caws.php?letter=Y">Y</a> <a href="caws.php?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">&nbsp;</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("","",""); 
mysql_select_db(""); 
 
$search=mysql_real_escape_string($_REQUEST["search"]);
 
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>&nbsp;';
				
		$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 . '">&#171;</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 . '">&#187;</a></li>', $totalPages);
		}
 
		return '<div class="pagination"><ul>' . $output . '</ul></div>';
	}
}
 
 
  
$page = 1;
$size = 3;
 
$r =  mysql_query( "SELECT COUNT(*) as total FROM caws WHERE name LIKE '%$search%' ORDER BY name " );
 
$total_records = mysql_fetch_assoc($r);
$total_records = $total_records["total"];
 
// we get the current page from $_GET
if (isset($_GET['page'])){
    $page = (int) $_GET['page'];
}
 
// create the pagination class
$pagination = new Pagination();
$pagination->setLink("search.php?search=$search&page=%s");
$pagination->setPage($page);
$pagination->setSize($size);
$pagination->setTotalRecords($total_records);
 
$SQL = "SELECT * FROM caws WHERE name LIKE '%$search%' 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>&nbsp;</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'>&nbsp;</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 )
 
      $navigation = $pagination->create_links();
      print "<tr>
      <td colspan='9' align='center' height='35' valign='middle'>
          $navigation
      </td>
</tr>"
 
?>
</table>
 
<font size='1'>CAWSearch 1.0.1</font>
</center>
 
</body>
</html>

Open in new window

0
Comment
Question by:m0tSiE
  • 8
  • 5
13 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 20754851
$SQL = "SELECT DISTINCT * FROM caws WHERE name LIKE '%$search%' ORDER BY name " . $pagination->getLimitSql();
 
0
 

Author Comment

by:m0tSiE
ID: 20755231
Thanks hielo, I tried using that query instead but it made no difference.

Should it not be the pagination count query that needs to be changed?

$r =  mysql_query( "SELECT COUNT(*) as total FROM caws WHERE name LIKE '%$search%' ORDER BY name " );
0
 
LVL 82

Expert Comment

by:hielo
ID: 20755246
Try adding DISTINCT to BOTH queries
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:m0tSiE
ID: 20755263
I've tried using these two, but it still makes no difference :(

$r =  mysql_query( "SELECT DISTINCT COUNT(*) as total FROM caws WHERE name LIKE '%$search%' ORDER BY name " );
 
$SQL = "SELECT DISTINCT * FROM caws WHERE name LIKE '%$search%' ORDER BY name " . $pagination->getLimitSql();
0
 
LVL 82

Expert Comment

by:hielo
ID: 20755415
I see what you are talking about. However, I don't understand the rationale of hiding Multiple intances of the wrestler. You seem to be focusing only on the "Name" field. However, from what I see on the table, Chris Jericho on the first row is different from Chris Jericho on the second row. Yes, it is referring to the same wrestler, but as a whole, the rows offer different set of information (attire, creator). That's why the DISTINCT is not working.
0
 

Author Comment

by:m0tSiE
ID: 20755478
Thanks hielo, Is there another way of doing it?

The main reason is that once all of the information is added to the database, say the pagination is set to show 50 results per page and the user is viewing all creations beginning with C. If there's a lot of a certain wrestler, then the user is going to have to browse through multiple pages to get to the next person. By hiding multiple occurances of the same wrestler it just makes it easier to find the one your looking for and keeps all the rows of the same wrestler on the same page so you can compare the attires, etc. to find the one you want.
0
 
LVL 82

Expert Comment

by:hielo
ID: 20755500
I guess it was not clear. The real problem is that the data "Per row" are distinct. For your purposes, "If there's a lot of a certain wrestler, then the user is going to have to browse through multiple pages to get to the next person."
it would make more sense if you just provide the wrester name and from after the user provides/selects the wrester they are interested in, then upon submission, you query the db for that wrester and return ALL the data fields for that wrestler only.
0
 

Author Comment

by:m0tSiE
ID: 20759525
The only thing is I was wanting to keep it all on a single page, instead of setting it up that way as most results will only have 1 entry.

Is it possible to change my code so instead of showing the rows in an expandable div, a second search is executed in the div where the $name displayed in the Multiple results row is used as the query?

That way it wouldn't count those rows in the main pagination?
0
 

Author Comment

by:m0tSiE
ID: 20760066
I've thought of another way, but I don't know if it's possible.

In the expandable div, all the multiple results are numbered. Is it possible to take the last number and add it to the pagination count?

eg. $size = 3;

then add the last number of the multiple results to it?

eg. Chris Jericho (2)

So the size would be 5?
0
 

Author Comment

by:m0tSiE
ID: 20763448
Ok, I think I am almost there.

I've managed to put together a code that counts the rows in the div's, etc.

At the moment i've put 6 entries into the database, these are:

Chris Benoit
Chris Jericho x3
Kurt Angle x2

Using the code I've added it adds all the single and multiple results up, so the above example is returned as 6 which I have displayed at the bottom of the page.

http://cawsearch.com/svr2008/search.php

The total rows including the hidden ones are added to the starting value which I have set to 3, this is shown as $perpage2.

The only problem I now have is when I try to do $size = $perpage2 to set the pagination to the correct amount it only picks it up as the original default value I set as 3.

Can anyone see why in my code it is still picking up the original 3 value instead of the 3 plus the added rows?

Many thanks,
Paul.
<table border="0" cellspacing="0" cellpadding="0" class="test">
	<tr>
		<td class="results-header-left" width="20">&nbsp;</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("","",""); 
mysql_select_db(""); 
 
$search=mysql_real_escape_string($_REQUEST["search"]);
 
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>&nbsp;';
				
		$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 . '">&#171;</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 . '">&#187;</a></li>', $totalPages);
		}
 
		return '<div class="pagination"><ul>' . $output . '</ul></div>';
	}
}
 
 
  
$page = 1;
$size = $perpage2;
$perpage2 = 3;
 
 
$r =  mysql_query( "SELECT COUNT(*) as total FROM caws WHERE name LIKE '%$search%' ORDER BY name " );
 
$total_records = mysql_fetch_assoc($r);
$total_records = $total_records["total"];
 
// we get the current page from $_GET
if (isset($_GET['page'])){
    $page = (int) $_GET['page'];
}
 
// create the pagination class
$pagination = new Pagination();
$pagination->setLink("search.php?search=$search&page=%s");
$pagination->setPage($page);
$pagination->setSize($size);
$pagination->setTotalRecords($total_records);
 
$SQL = "SELECT * FROM caws WHERE name LIKE '%$search%' ORDER BY name " . $pagination->getLimitSql();
 
$result = mysql_query($SQL); 
 
$totalcountmulti = 0;
 
$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)
     {
 
		$thiscount = count($rows);
		$totalcountmulti += $thiscount;
		$totalcountmulti -= 1;
 
       // print the name's row
       print "
         <tr>
				<td class=results-show-left>&nbsp;</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>- (" . count($rows) . " 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'>&nbsp;</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 )
 
      $navigation = $pagination->create_links();
 
$perpage2 += $totalcountmulti;
 
      print "<tr>
      <td colspan='9' align='center' height='35' valign='middle'>
          $navigation
 
			Multiple Results in div = $perpage2
 
      </td>
</tr>"
 
?>
</table>

Open in new window

0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 20765863
>>it only picks it up as the original default value I set as 3.
On the code you posted you have:
$page = 1;
$size = $perpage2;
$perpage2 = 3;

which basically sets $size to 0 because $perpage2 has not been initialized previously. You then have:
$pagination->setSize($size);

So I don't know how you are getting 3. The only way that would happen is if you updated your code after your last post/paste to:
$page = 1;
$perpage2 = 3;
$size = $perpage2;

>>Can anyone see why in my code it is still picking up the original 3 value instead of the 3 plus the added rows?
That would give you all the rows. Namely, $total_records. So, $total_records has the number/quantity your are seeking. I just don't understand what for?
0
 

Author Comment

by:m0tSiE
ID: 20772800
I was wanting to set the pagination to 3, then using the code add in the amount of multiple rows to take it up, so there would be 3 unique results not including the multiple results. Although I guess that wouldn't work as it would have already loaded 3.
0
 

Author Closing Comment

by:m0tSiE
ID: 31425415
Cheers hielo :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question