Page 1 of 1

[56K WARN] Table with previous 1,2,3 next function...

Posted: Tue Jun 28, 2005 10:30 pm
by kill_bill
I have problem in doing table with function above, so i'm so afraid i can't do it.. so perhaps any of you can help me to find out this function for me..

Actually, I'm a newbie here...:)

Posted: Wed Jun 29, 2005 2:52 am
by djot
search this forum for "pagination" or "paging"
or try http://www.google.com/search?&q=php+pagination
or try sourceforge.net, hotscripts.com

Posted: Wed Jun 29, 2005 3:22 am
by s.dot
basically you'll need to set a variable for how many you'd like per page

find the total number of rows your query retrives, divide by the variable (this will give you total number of pages)

then loop through till you reach that number, something like

Code: Select all

for($i = 1; $i < $totalpages; $i++)
{
 echo "<a href=\"page.php?page=$i\">$i</a> ";
}
That's it basically. However there are some very nice pre-made pagination scripts already made if you google it.

Posted: Wed Jun 29, 2005 5:57 am
by pleigh
i think its pagination.....if you like, i can post some codes for you...

Posted: Wed Jun 29, 2005 9:45 pm
by kill_bill
Yup.. you are correct.. that is my pleasure if you can post me some.. :)

Posted: Thu Jun 30, 2005 4:16 am
by pleigh
you can dieasily dissect this code and revise it to fit your needs....i hope this will help...

Code: Select all

function adminpagination()
{	

//start of pagination
$display = 10;
	
	
	if (isset($_GET['np'])) 
	{ 
		$num_pages = $_GET['np'];
	} 
	else 
	{ 
		$query = "SELECT * FROM posts"; 
		$query_result = mysql_query ($query);
		$num_records = @mysql_num_rows ($query_result);
		
		if ($num_records > $display) 
		{ 
			$num_pages = ceil ($num_records/$display);
		} 
		else 
		{
			$num_pages = 1;
		}
	}
	
	
	if (isset($_GET['s'])) 
	{ 
		$start = $_GET['s'];
	} 
	else 
	{
		$start = 0;
	}
			
	// Make the query.
	$query = "SELECT DATE_FORMAT(postupdate, '%M %e, %Y - %l:%i %p'), topic, postID, firstname FROM posts AS p, users AS u
			WHERE p.userID = u.userID ORDER BY postupdate DESC LIMIT $start, $display";		
	$result = @mysql_query ($query); 
	$num = mysql_num_rows ($result); 
	
	if ($num > 0) 
	{ 	
		if ($num_pages > 1) 
		{			
			
			$current_page = ($start/$display) + 1;
			
			echo '<table border=0 cellpadding=2 cellspacing=0 bordercolor=#ffffff><tr>';
			if ($current_page != 1) 
			{
				echo '<td class=tableborder><a href="report.php?s=' . ($start - $display) . 
				'&np=' . $num_pages . '" class=under><b/>Previous</a></td> ';
			}
			
			
			for ($i = 1; $i <= $num_pages; $i++) 
			{
				if ($i != $current_page) 
				{
					echo '<td class=tableborder><a href="report.php?s=' . (($display * ($i - 1))) . 
					'&np=' . $num_pages . '" class=under><b/>' . $i . '</a></td> ';
				} 
				else 
				{
					echo '<td bgcolor="yellow" class=tableborder><b/>'. $i . ' </td>';
				}
			}
			
			
			if ($current_page != $num_pages) 
			{
				echo '<td class=tableborder><a href="report.php?s=' . ($start + $display) . 
				'&np=' . $num_pages . '" class=under><b/>Next</a></td>';
			}
			echo '</tr></table>';
									
		}		
		
		echo "<table width=100% border=1 bordercolor=#336699 cellpadding=0 cellspacing=0 class=tablehead>
		<tr align=center class=tablehead><td width=20% class=tableborder><table><tr><td><b>NAME</b></td></tr></table></td>
			<td width=50% class=tableborder><table><tr><td><b>TOPIC</b></td></tr></table></td>
			<td width=10% class=tableborder><table><tr><td><b>REPLIES</b></td></tr></table></td>
			<td width=20% class=tableborder><table><tr><td><b>DATE</b></td></tr></table></td></tr>
			</table>";
		
		echo '<table width=100% border=1 bordercolor=#336699 cellpadding=0 cellspacing=0 class=tableborder>';
		while ($row = mysql_fetch_array($result, MYSQL_NUM)) 
		{	
									
			$row[0] = '<font size=1>'.$row[0].'</font>';
  			echo "
			<tr><td width=20% class=tableborder align=center><table><tr><td><b><a href=\"\" class=\"under\">".strtolower($row[3])."</a><b></td></tr></table></td>
			<td width=50% class=tableborder><table><tr><td><a href=\"reportview.php?pid={$row[2]}\" class=\"under\">$row[1]</a></td></tr></table></td>
			<td width=10% class=tableborder align=center><table><tr><td>".replies($row[2])."</td></tr></table></td>
			<td width=20% class=tableborder><table><tr><td>$row[0]</td></tr></table></td></tr>";			
		}
		echo '</table>';
	
		mysql_free_result ($result); 	
	} 
	else 
	{ 
		echo '<h3>There are no records to show.</h3>'; 
	}
	
	mysql_close(); 
}

Posted: Thu Jun 30, 2005 11:53 am
by timvw

Posted: Mon Jul 04, 2005 3:18 am
by kill_bill
hi timw... nice script dude.. but can u give me the database... if the db was contained there.. i'm so sorry...

i hope u will help a newbie here (me)... thanks

My page should be like this
Image

Posted: Mon Jul 04, 2005 6:52 am
by smo
There is a tutorial here and you can download the source with sql files also.
PHP paging

Check the advanced paging also if you have more number of records and not in a position to show all the links at a time.
http://www.plus2net.com/php_tutorial/php_paging_adv.php

Posted: Mon Jul 04, 2005 9:00 am
by timvw
If i'm not mistaken there should be a /dbclasses/dump.sql file ;)