954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Page Number

Hi, i created the page which is display some information from database with some rules in the end of page i putted the command that it is show how many page that i have.

so, i decide to add next and previous in the sides of page numbers and also i wanna mark active page for visitor (for ex : type active page with bold style)

here is the code :

<?php 
include "db.php";
 
//Rows
$qtyRow = '<tr>';
$priceRow = '<tr>';
 
$nn=6; //Number of items, we split this later
 
$s=mysql_query("SELECT * FROM `test1`");
 
$c=mysql_num_rows($s);
 
if($c%$nn==0){
	$cc=$c/$nn;	
}else{
	$cc=$c/$nn+1;	
}
 
//$cc : Number of pages
 
$ss=@$_REQUEST['ss']; //Start position (eg: 6)
$other_tables = "";
 
if($ss=="" || $ss==null){
	$ss = 0; //Set to zero because it is incremented later
}
 
//Pages
echo "<table border=\"1\" align=\"center\">";
$sql=mysql_query("SELECT * FROM `test1` ORDER BY `id` DESC LIMIT $ss,$nn");
$inc = 0;
while($r=mysql_fetch_array($sql)){
	$id=$r['id'];  
	$name=$r['name'];
	if($inc == 0){
		$qtyRow .= "<tr>";
		$priceRow .= "<tr>";
	}
	$qtyRow .= "<td>$id</td>";
	$priceRow .= "<td>$name</td>";
	++$inc;
	if($inc == 3 || $inc == 6 || $inc == mysql_num_rows($sql)){
		//Display Table
		echo $qtyRow."</tr>";
		echo $priceRow."</tr>";
		echo "</table>";
 
		//To remove extra table
		if(mysql_num_rows($sql) <= 3){
			$inc = 7;
		}
 
		//Reset
		if($inc == 3){
			echo "<table border='1' align='center'>";
			$qtyRow = "<tr>";
			$priceRow = "<tr>";
		}
	}
}
echo "</table>";
$j=0;
echo"page : ";
for($i=1;$i<=$cc;$i++){
	echo"<a href=\"select.php?ss=$j\">$i</a>";
	echo"|";
	$j=$j+$nn; 
}
?>
mehdi.yazdani
Light Poster
25 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

thanks my friend but unfortunately i couldn't assemble that code in my page !
i liked that style, so how can i edit my codes to reach that style ??
could yo help me with this problem ??

mehdi.yazdani
Light Poster
25 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 
thanks my friend but unfortunately i couldn't assemble that code in my page ! i liked that style, so how can i edit my codes to reach that style ?? could yo help me with this problem ??


follow the tutorial and forget your code for a while. Once you finish the tut. and know how things works, you can accomodate changes and additions to fit your needs. That is the way we learn :)

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

please help me to set active button for active page. page that you are in it.
and other style for other pages, page that you are not.

<?php
$j=0;
	
for($i=1;$i<=$cc;$i++)
{
	?> <li><a class="button active small" href="showcodes.php<? echo "?ss=$j"; ?>"><span><? echo"$i"; ?></span></a></li>
       <li><a class="button tertiary small" href="showcodes.php<? echo "?ss=$j"; ?>"><span><? echo"$i"; ?></span></a></li>
    
     <? 
	
	$j=$j+$nn; 
}}
?>
mehdi.yazdani
Light Poster
25 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

please help me to set active button for active page. page that you are in it. and other style for other pages, page that you are not.

<?php
$j=0;
	
for($i=1;$i<=$cc;$i++)
{
	?> <li><a class="button active small" href="showcodes.php<? echo "?ss=$j"; ?>"><span><? echo"$i"; ?></span></a></li>
       <li><a class="button tertiary small" href="showcodes.php<? echo "?ss=$j"; ?>"><span><? echo"$i"; ?></span></a></li>
    
     <? 
	
	$j=$j+$nn; 
}}
?>


You mean styling the button? That is CSS and differs from person to person!

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

No, u know in this form i have 2 style for my buttons one of them is active style i want to set active style for page that i already visiting it.

<li><a class="button active small" href="showcodes.php<? echo "?ss=$j"; ?>"><span><? echo"$i"; ?></span></a></li>

this is the style which used for active button .

mehdi.yazdani
Light Poster
25 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

its CSS issue try and adapt this code to your need

<style>
.button_active_small{
    font-weight:bold;
    text-decoration: none;
    color:maroon;
    border:1px;
}
</style>

<?php $j=23; $i=100; ?>
 <a class="button_active_small" href="<?php echo 'showcodes.php?ss='.$j; ?>"><?php echo $i; ?> </a>
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

My dear i create css style i dont need to add any styles
Please answer my question it is not about creating any styles
As i said i create 2 style for my buttons class="button_active_small" style and class="button tertiary small" so, now i want to set first style for page that i already visiting it that with FOR LOOP COMMAND created and the other style for other pages.

mehdi.yazdani
Light Poster
25 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 
My dear i create css style i dont need to add any styles Please answer my question it is not about creating any styles As i said i create 2 style for my buttons class="button_active_small" style and class="button tertiary small" so, now i want to set first style for page that i already visiting it that with FOR LOOP COMMAND created and the other style for other pages.


do you pay me for anything I contribute?:(

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

if you cant answer or you dont know what to do you can say i dont have any idea about that and dont ever never waste your and any body's time .

mehdi.yazdani
Light Poster
25 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 
if you cant answer or you dont know what to do you can say i dont have any idea about that and dont ever never waste your and any body's time .

I'm off the bandwagon!

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You