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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kill_bill
Forum Newbie
Posts: 6
Joined: Tue Jun 28, 2005 10:17 pm
Location: Malaysia
Contact:

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

Post 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...:)
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post 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
Last edited by djot on Wed Jun 29, 2005 6:03 am, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

i think its pagination.....if you like, i can post some codes for you...
User avatar
kill_bill
Forum Newbie
Posts: 6
Joined: Tue Jun 28, 2005 10:17 pm
Location: Malaysia
Contact:

Post by kill_bill »

Yup.. you are correct.. that is my pleasure if you can post me some.. :)
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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(); 
}
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

User avatar
kill_bill
Forum Newbie
Posts: 6
Joined: Tue Jun 28, 2005 10:17 pm
Location: Malaysia
Contact:

Post 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
smo
Forum Newbie
Posts: 20
Joined: Tue May 31, 2005 11:02 pm

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If i'm not mistaken there should be a /dbclasses/dump.sql file ;)
Post Reply