Page 1 of 1

scipt for pagination

Posted: Tue Feb 22, 2005 11:17 pm
by pleigh
hi there

just wanna share some script for paginatioin, i spent 2 days searching for the right one fit for a newbie like me, i found it last night somewhere in the net, can't remember the site... :lol:

anyway, i modified some codes.simple, yet i'm satisfied, and i think its the code is messy...for a newbie looking for a nice script, this might help.

Code: Select all

if ($rowї0])
		{
			if(isset($_GETї"p"]))
			{
    			$p = intval($_GETї"p"]);
			}
			else
			{
  	  			$p = 1;
			}

			$limit = 10;
			$limitvalue = ($p * $limit - ($limit));

			$result_count = mysql_query("SELECT count(*)as vv FROM posts");
			$myrow=mysql_fetch_array($result_count);
			$totalrows = $myrowї"vv"];

			

			$result = mysql_query("SELECT DATE_FORMAT(date, '%M %D, %Y'), title, postID, firstname FROM posts AS p, users AS u 
			WHERE p.userID = u.userID ORDER BY date DESC LIMIT $limitvalue, $limit") or die("Error: " . mysql_error());

			if(mysql_num_rows($result) == 0)
			{
  	  			echo("Nothing to Display!");
			}


			echo "<tr align=center><td width=20%><table><tr><td><b>NAME</b></td></tr></table></td>
			<td width=60%><table><tr><td><b>TOPIC</b></td></tr></table></td>
			<td width=20%><table><tr><td><b>DATE</b></td></tr></table></td></tr>";
			
			while($row = mysql_fetch_array($result, MYSQL_NUM))
			&#123;    											
				echo "<tr><td width=20%><table><tr><td><b><a href="" class="under">$row&#1111;3]</a><b></td></tr></table></td>
				<td width=60%><table><tr><td><a href="reportview.php?pid=&#123;$row&#1111;2]&#125;" class="under">$row&#1111;1]</a></td></tr></table></td>
				<td width=20%><table><tr><td>$row&#1111;0]</td></tr></table></td></tr>";  
			&#125;
			
			echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
  			echo '<tr>';
    			echo '<td width="50%" align="left">';
				echo "page no. $p<br>";
				echo '</td>';
    			
				echo '<td width="50%" align="right">';
				
				if($p == 1)
				&#123;
    				NULL;
				&#125;
				else
				&#123;
    				$pageprev = $p-1;
    				echo("<a href="report.php?p=$pageprev" class=under>PREVIOUS</a>&nbsp;");
				&#125;

				$numofpages = ($totalrows / $limit) + 1;
			
				for($i = 1; $i <= $numofpages; $i++)
				&#123;
    				if($i == $p)
    				&#123;
        				echo($i."&nbsp;");
    				&#125;
    				else
    				&#123;
        				echo("<a href="report.php?p=$i" class=under>$i</a>&nbsp;");
    				&#125;
				&#125;

				if(($totalrows - ($limit * $p)) > 0)
				&#123;
    				$pagenext = $p+1;
    				echo("<a href="report.php?p=$pagenext" class=under>NEXT</a>");
				&#125;
				else
				&#123;
    				NULL;
				&#125;
				
				echo '</td>';
  			echo '</tr>';
			echo '</table>';
						
			mysql_free_result($result);
			
				
			&#125;
			else
			&#123;
				echo 'system error!<br>'.mysql_error();
			&#125;
			mysql_close();
good day!

pleigh :D