Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php/mysql pagination problem :I get the links but the links dont work can anyone please help me?

Posted on 2008-11-13
28
Medium Priority
?
311 Views
Last Modified: 2013-12-13
I have gone through many pagination tutorials and some code, I am trying to impliment pagination on my database results- I'm missing something- I've tried this for many many long hours without any success - for a beginner is a beginner! :0( .
I get the links, the links don't display any records even though they take me to the next page. I don't know whether its the link issue .... <a href=\"$PHP_SELF?page=" . $i . "\">" . $i . "</a>
Can someone please help me understand and solve my problem?
//some code
 
$limit = 3;                
    $result_count = mysql_query('SELECT * FROM table WHERE fieldname = "'. $_POST['fieldname'] .'"');
    $totalrows = mysql_num_rows($result_count);
    if(empty($page)){ 
        $page = 1; 
    } 
	$limitvalue = $page * $limit - ($limit);  
	
 
$query = 'SELECT * FROM table WHERE fieldname = "'. $_POST['fieldname'] .'" LIMIT ' . $limitvalue . ',' .  $limit;
		
$result = mysql_query($query)
			or die (mysql_error());
$num_results = mysql_num_rows($result);
 
if($num_results == 0) {
	echo "<table border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:16px;'>";
	echo "<tr><td>";
	echo "There are no records to display with reference to your search!";
	echo "</tr></td>";
	echo "</table>";
} else{
	echo "<table border='5' align='center' cellpadding='2' cellspacing='1' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'>";
	//	echo "<table align=center bgcolor=#FF9900 border='1'>";
	 
	// keeps getting the next row until there are no more to get
	while($row = mysql_fetch_array($result)) {
	
		echo "<tr> <th>fieldname</th> <th>fieldname</th>  <th>fieldname</th> <th>fieldname</th><th>fieldname</th> <th>fieldname</th> <th>fieldname</th><th>fieldname</th> <th>fieldname</th><th>fieldname </th><th>fieldname</th></tr>";
		echo "<tr><td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['fieldname'];
		echo "</td>";
		echo "</tr>
	
	}
	echo "</table>";
	}	
	}	
		echo "<table  align='center'>";
		echo "<tr><td  align='center'><p align=center>";
		
 
						if($page != 1) {  
								$pageprev = $page - 1; 
								 
								echo("<a href=\"$PHP_SELF?page=" . $pageprev . "\">PREV " . $limit . "</a>&nbsp;&nbsp;&nbsp;");  
							} else { 
								echo("PREV " . $limit . "&nbsp;&nbsp;&nbsp;"); 
							} 
 
							$numofpages = $totalrows / $limit;  
							 
							for($i = 1; $i <= $numofpages; $i++) { 
								if($i == $page) { 
									echo($i . " "); 
								} else { 
									echo("<a href=\"$PHP_SELF?page=" . $i . "\">" . $i . "</a> "); 
								} 
							} 
 
 
							if(($totalrows % $limit) != 0) { 
								if($i == $page) { 
									echo($i." "); 
								} else { 
									echo("<a href=\"$PHP_SELF?page=" . $i . "\">" . $i . "</a> "); 
								} 
							} 
 
							if(($totalrows - ($limit * $page)) > 0) { 
								$pagenext = $page + 1; 
								echo("&nbsp;&nbsp;<a href=\"$PHP_SELF?page=" . $pagenext . "\">NEXT " . $limit . "</a>");  
							} else { 
								echo("&nbsp;&nbsp;NEXT " . $limit);  
							}					
								
		
		echo "</p></td></tr>";
		echo "</table>";

Open in new window

0
Comment
Question by:786aslamkhan
  • 14
  • 7
  • 6
  • +1
28 Comments
 
LVL 9

Expert Comment

by:mgonullu
ID: 22948008
Why not shift the quotations:
and make it like this
 echo("<a href=\"$PHP_SELF?page= . $pageprev . "\">PREV " 

0
 

Expert Comment

by:aroldus
ID: 22948037
I think you type $PHP_SELF
when your really want to type $_SERVER['PHP_SELF']
0
 

Author Comment

by:786aslamkhan
ID: 22948129
Thanks mgonullu I tried every possible way to change the quote marks- but it does'nt work :(
Thank you anyway for your time and attention.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:786aslamkhan
ID: 22948263
aroldus thanks for your attention!
I have tried $PHP_SELF with register_globals ON and I have also tried with   $_SERVER['PHP_SELF']
It just is not working.
I don't know where I'm going wrong.
Thanks a lot for your time buddy!
0
 

Author Comment

by:786aslamkhan
ID: 22948280
I think I'm not getting it 'cause i'm probably messing up the quotation marks - or the syntax.
0
 
LVL 3

Expert Comment

by:icarey
ID: 22948703
I see a couple of syntax errors
in your code snippet above
line 63 echo "</tr> should be echo "</tr>";

line 67 } I have commented this out //} unsure if it relates to something a lot further up the code

I have changed $PHP_SELF to $_SERVER['PHP_SELF']

All changes in the snippet below

I haven't done any testing on this you may like to try
//some code
 
$limit = 3;                
    $result_count = mysql_query('SELECT * FROM table WHERE fieldname = "'. $_POST['fieldname'] .'"');
    $totalrows = mysql_num_rows($result_count);
    if(empty($page)){ 
        $page = 1; 
    } 
        $limitvalue = $page * $limit - ($limit);  
        
 
$query = 'SELECT * FROM table WHERE fieldname = "'. $_POST['fieldname'] .'" LIMIT ' . $limitvalue . ',' .  $limit;
                
$result = mysql_query($query)
                        or die (mysql_error());
$num_results = mysql_num_rows($result);
 
if($num_results == 0) {
        echo "<table border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:16px;'>";
        echo "<tr><td>";
        echo "There are no records to display with reference to your search!";
        echo "</tr></td>";
        echo "</table>";
} else{
        echo "<table border='5' align='center' cellpadding='2' cellspacing='1' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'>";
        //      echo "<table align=center bgcolor=#FF9900 border='1'>";
         
        // keeps getting the next row until there are no more to get
        while($row = mysql_fetch_array($result)) {
        
                echo "<tr> <th>fieldname</th> <th>fieldname</th>  <th>fieldname</th> <th>fieldname</th><th>fieldname</th> <th>fieldname</th> <th>fieldname</th><th>fieldname</th> <th>fieldname</th><th>fieldname </th><th>fieldname</th></tr>";
                echo "<tr><td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td><td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>"; 
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td><td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>"; 
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "</tr>";
        
        }
        echo "</table>";
        //}       
        }       
                echo "<table  align='center'>";
                echo "<tr><td  align='center'><p align=center>";
                
 
                                                if($page != 1) {  
                                                                $pageprev = $page - 1; 
                                                                 
                                                                echo("<a href=\"$_SERVER['PHP_SELF']?page=" . $pageprev . "\">PREV " . $limit . "</a>   ");  
                                                        } else { 
                                                                echo("PREV " . $limit . "   "); 
                                                        } 
 
                                                        $numofpages = $totalrows / $limit;  
                                                         
                                                        for($i = 1; $i <= $numofpages; $i++) { 
                                                                if($i == $page) { 
                                                                        echo($i . " "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER['PHP_SELF']?page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
 
                                                        if(($totalrows % $limit) != 0) { 
                                                                if($i == $page) { 
                                                                        echo($i." "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER['PHP_SELF']?page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
                                                        if(($totalrows - ($limit * $page)) > 0) { 
                                                                $pagenext = $page + 1; 
                                                                echo("  <a href=\"$_SERVER['PHP_SELF']?page=" . $pagenext . "\">NEXT " . $limit . "</a>");  
                                                        } else { 
                                                                echo("  NEXT " . $limit);  
                                                        }                                       
                                                                
                
                echo "</p></td></tr>";
                echo "</table>";

Open in new window

0
 

Author Comment

by:786aslamkhan
ID: 22966129
thanks icarey! for your help and time- I did try the code as you suggested, but but it doesn't work- sorry for the delayed response but I had to attend to some unscheduled but critical work that kept me away from my machine and laptop- it was unavoidable.
Thanks though I appreciate your help!
0
 
LVL 3

Expert Comment

by:icarey
ID: 22966535
For testing purposes I made a database, with a table and fields for my testing. I tested the code below and all works

I have commented the code and changes so you can see the differences. See how you go.

Ivan
<?php
 
$limit = 3;
 
	// simpler to write like this
	$fieldname = $_REQUEST["fieldname"];
	$sql1 = "SELECT * FROM pagination WHERE fieldname = '$fieldname'";
    $result_count = mysql_query($sql1);
    $totalrows = mysql_num_rows($result_count);
	
	
	// must reference $_GET["page"] as it will be sent from the page links
    if(empty($_GET["page"]))
	{ 
        // first time page is viewed
		$page = 1;
	}
	else
	{
		//value sent by the page links
		$page = $_GET["page"];
    } 
 
	// small change here
	$limitvalue = ($page * $limit) - $limit;  
        
 
// simplified here the sql statement
 $query = "SELECT * FROM pagination WHERE fieldname = '$fieldname' LIMIT $limitvalue, $limit";
                
$result = mysql_query($query)
    or die (mysql_error());
$num_results = mysql_num_rows($result);
 
if($num_results == 0) {
        echo "<table border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:16px;'>";
        echo "<tr><td>";
        echo "There are no records to display with reference to your search!";
        echo "</tr></td>";
        echo "</table>";
} else{
        echo "<table border='5' align='center' cellpadding='2' cellspacing='1' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'>";
        //      echo "<table align=center bgcolor=#FF9900 border='1'>";
         
        // keeps getting the next row until there are no more to get
        while($row = mysql_fetch_array($result)) {
 
				// I have changed some of the fieldnames below only for my testing, change back to yours
 
                echo "<tr> <th>fieldname</th> <th>fieldname</th>  <th>fieldname</th> <th>fieldname</th><th>fieldname</th> <th>fieldname</th> <th>fieldname</th><th>fieldname</th> <th>fieldname</th><th>fieldname </th><th>fieldname</th></tr>";
                echo "<tr><td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td><td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname2'];
                echo "</td>"; 
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname3'];
                echo "</td><td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>"; 
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "<td bgcolor='#FFFFFF'>"; 
                echo $row['fieldname'];
                echo "</td>";
                echo "</tr>";
        
        }
        echo "</table>";
        //}       
        }       
                echo "<table  align='center'>";
                echo "<tr><td  align='center'><p align=center>";
												
												// added fieldname=$fieldname here to the link so that it gets sent back to the sql's above
                                                if($page != 1) {  
                                                                $pageprev = $page - 1; 
                                                                                                                        
																echo("<a href=\"$_SERVER[PHP_SELF]?fieldname=$fieldname&page=" . $pageprev . "\">PREV " . $limit  . "</a>   ");  
                                                        } else { 
                                                                echo("PREV " . $limit . "   "); 
                                                        } 
 
                                                        $numofpages = $totalrows / $limit;  
                                                         
                                                        for($i = 1; $i <= $numofpages; $i++) { 
                                                                if($i == $page) { 
                                                                        echo($i . " "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?fieldname=$fieldname&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
 
                                                        if(($totalrows % $limit) != 0) { 
                                                                if($i == $page) { 
                                                                        echo($i." "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?fieldname=$fieldname&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
                                                        if(($totalrows - ($limit * $page)) > 0) { 
                                                                $pagenext = $page + 1; 
                                                                echo("  <a href=\"$_SERVER[PHP_SELF]?fieldname=$fieldname&page=" . $pagenext . "\">NEXT " . $limit . "</a>");  
                                                        } else { 
                                                                echo("  NEXT " . $limit);  
                                                        }                                       
                                                                
                
                echo "</p></td></tr>";
                echo "</table>";
				
				//below for debugging only uncomment to see php variables
				//phpinfo();
?>				

Open in new window

0
 
LVL 3

Expert Comment

by:icarey
ID: 22966541
one other note in the page links I changed $_SERVER['PHP_SELF']  to $_SERVER[PHP_SELF] ( removed the ' ')
0
 

Author Comment

by:786aslamkhan
ID: 22973546
Thank you for your help Ivan- I'm grateful for the effort and time you have devoted by creating the database etc. I have to apologize for not responding earlier as I have an ongoing litigation regarding my ancestral property and I have to be in court from time to time- unfortunately I have had to be in court and have not been able to respond earlier- I'm very sorry to keep you waiting for the response.
As you say your code works- I'm sure it does and I'm sure I'm doing something stupid or careless because it still is not working at my end.
I have made the following changes:

line6: replaced my fieldname in the $_REQUEST["fieldname"];.
line7: replace my tablename (instead of pagination) and also the fieldname.
line29: I have changed the tablename and fieldname to mine.
lines 104,112,117 and 121: I have changed the fieldname to my fieldname appropriately.
The table result displays correctly.
The links display correctly, but the links take me to a page without any result and aslo the links don't work.
I can't figure out what I'm doing wrong.
Sorry for being a nut!
Aslam.
0
 

Author Comment

by:786aslamkhan
ID: 22973563
It being the weekend, just to clarify, I had to be in court on Saturday and had to spend time digging out some old documents right through Sunday.
0
 
LVL 3

Expert Comment

by:icarey
ID: 22974387
Aslam
attach your new code so I can see exactly what is happening also your table schema would help I can then place it into my test environment to duplicate what you have.
I can place my own test data
your table names and filed names and properties would help.

0
 

Author Comment

by:786aslamkhan
ID: 22976714
Ivan I have attached my file and the table schema- with a few details obviously masked. I hope we can identify where I'm missing something.
Thanks for your patience!
<? session_start();?>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></HEAD>
<style type="text/css">
<!--
.style1 {
	color: #0000CC;
	font-weight: bold;
}
body {
	background-color: #CCCCCC;
}
.style2 {font-size: medium}
.style3 {
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style5 {
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
}
.style7 {
	font-size: 12px;
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
-->
</style>
 
<title>*******</title>
<BODY>
<table width="500" border="0" align="center">
  <tr>
    <td><div align="center" class="style1">
      <h2 class="style2 style3"></h2> 
    </div></td>
  </tr>
</table>
<p>
  <?php
if (isset($_POST['******'])) {
 
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
 
$limit = 3;
 
	// simpler to write like this
	$fieldname = $_REQUEST["ls_cut"];
	$sql1 = "SELECT * FROM ls WHERE ls_cut = '$fieldname'";
    $result_count = mysql_query($sql1);
    $totalrows = mysql_num_rows($result_count);
	
	
	// must reference $_GET["page"] as it will be sent from the page links
    if(empty($_GET["page"]))
	{ 
        // first time page is viewed
		$page = 1;
	}
	else
	{
		//value sent by the page links
		$page = $_GET["page"];
    } 
 
	// small change here
	$limitvalue = ($page * $limit) - $limit;  
        
 
// simplified here the sql statement
 $query = "SELECT * FROM ls WHERE ls_cut = '$fieldname' LIMIT $limitvalue, $limit";
                
$result = mysql_query($query)
    or die (mysql_error());
$num_results = mysql_num_rows($result);
 
if($num_results == 0) {
        echo "<table border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:16px;'>";
        echo "<tr><td>";
        echo "There are no records to display with reference to your search!";
        echo "</tr></td>";
        echo "</table>";
} else{
        echo "<table border='5' align='center' cellpadding='2' cellspacing='1' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'>";
        //      echo "<table align=center bgcolor=#FF9900 border='1'>";
         
  while($row = mysql_fetch_array($result)) {
 
		echo "<tr> <th>ParcelNo</th> <th>Type</th>  <th>Cut</th> <th>Clarity<br>From</th><th>Clarity<br>To</th> <th>Colour<br>From</th> <th>Colour<br>To</th><th>Plus</th> <th>Minus</th><th>MM X</th><th>MM</th></tr>";
		echo "<tr><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_parcel_no'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_type'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_cut'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_clarity_from'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_clarity_to'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_colour_from'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_colour_to'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sieve_size'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sieve_size_max'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mm'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mm_to'];
		echo "</td>";
		echo "</tr><br><tr>";
		echo "<th>Table %</th><th>Total<br>Depth</th> <th>Crown<br>Angle</th><th>Crown<br>Height</th><th>Pav<br>Depth</th>  <th>Pav<br>Angle</th><th>Girdle</th>  <th>Culet</th></tr><tr>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['percent_table'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['total_depth'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['crown_angle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['crown_ht'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['pav_depth'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['pav_angle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['girdle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['culet'];
		echo "</td></tr><tr>";
		echo "<th>mment</th><th>Cut<br>Grade</th> <th>Polish<br>Grade</th><th>Symm</th><th>Table</th>  <th>Cert</th><th>Flo</th>  <th>Total<br>Wt</th> <th>Total<br>Pcs</th>  <th>Edit</th> <th>Delete</th></tr><tr>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mment'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['cut_grade'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['polish_grade'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sym'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['dia_table'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['cert'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['flo'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>";
		echo $row['ls_total_wt'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_total_pcs'];
		echo "<td bgcolor='#FFFFFF'>"; 
		echo "<a href=editfile.php?id=";
		echo $row['ls_id'];
		echo ">Edit</a>";
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo "<a onclick=\"return confirm('Are you sure you want to delete this parcel?');\" href=\"some.php?id=";
		echo $row['id'];
		echo "\">Delete</a>";
		echo "</td>";
		echo "</tr>";
		echo "<tr><td colspan='11' bgcolor='#333333'>&nbsp;</td>";
		echo "</tr>";
	}
	
	    echo "</table>";
	}	
	}
		echo "<table  align='center'>";
        echo "<tr><td  align='center'><p align=center>";
												
												// added fieldname=$fieldname here to the link so that it gets sent back to the sql's above
                                                if($page != 1) {  
                                                                $pageprev = $page - 1; 
                                                                                                                        
																echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$fieldname&page=" . $pageprev . "\">PREV " . $limit  . "</a>   ");  
                                                        } else { 
                                                                echo("PREV " . $limit . "   "); 
                                                        } 
 
                                                        $numofpages = $totalrows / $limit;  
                                                         
                                                        for($i = 1; $i <= $numofpages; $i++) { 
                                                                if($i == $page) { 
                                                                        echo($i . " "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$fieldname&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
 
                                                        if(($totalrows % $limit) != 0) { 
                                                                if($i == $page) { 
                                                                        echo($i." "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$fieldname&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
                                                        if(($totalrows - ($limit * $page)) > 0) { 
                                                                $pagenext = $page + 1; 
                                                                echo("  <a href=\"$_SERVER[PHP_SELF]?ls_cut=$fieldname&page=" . $pagenext . "\">NEXT " . $limit . "</a>");  
                                                        } else { 
                                                                echo("  NEXT " . $limit);  
                                                        }                                       
                                                                
                
                echo "</p></td></tr>";
                echo "</table>";
				
				//below for debugging only uncomment to see php variables
				//phpinfo();
 
?></p>
 
</BODY>
</HTML>
 
 
//table schema
-- 
-- Table structure for table `ls`
-- 
 
CREATE TABLE `ls` (
  `ls_id` int(50) NOT NULL auto_increment,
  `from_parcel_no` varchar(20) default NULL,
  `date_sorted` date default NULL,
  `ls_parcel_no` varchar(20) NOT NULL,
  `ls_type` char(25) NOT NULL,
  `ls_cut` char(25) NOT NULL,
  `ls_clarity_from` char(25) NOT NULL,
  `ls_clarity_to` char(25) NOT NULL,
  `ls_colour_from` char(25) NOT NULL,
  `ls_colour_to` char(25) NOT NULL,
  `ls_total_wt` decimal(6,3) NOT NULL,
  `ls_total_pcs` smallint(10) unsigned NOT NULL,
  `sieve_size` varchar(5) NOT NULL,
  `sieve_size_max` varchar(5) NOT NULL,
  `mm` decimal(5,2) default NULL,
  `mm_to` decimal(5,2) default NULL,
  `cert` varchar(10) default NULL,
  `cut_grade` varchar(15) default NULL,
  `polish_grade` varchar(15) default NULL,
  `sym` varchar(10) default NULL,
  `dia_table` varchar(10) default NULL,
  `mment` varchar(20) default NULL,
  `flo` varchar(10) default NULL,
  `percent_table` varchar(5) default NULL,
  `total_depth` varchar(5) default NULL,
  `crown_angle` varchar(5) default NULL,
  `crown_ht` varchar(5) default NULL,
  `pav_depth` varchar(5) default NULL,
  `pav_angle` varchar(5) default NULL,
  `girdle` varchar(20) default NULL,
  `culet` varchar(20) default NULL,
  PRIMARY KEY  (`ls_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ;

Open in new window

0
 

Expert Comment

by:aroldus
ID: 22978991
Awesome! I placed it into my test server, I make some dump data in the table and IT WORKS CORRECTLY!!. What kind of text do you get on $fieldname as ls_cut? can you give some examples?
0
 

Expert Comment

by:aroldus
ID: 22979038
uhmmm. I made the test changin if($_POST[*****]) with if(1).
The links only can send parameters on get method. When you click it you loose the $_POST parameter so you dont enter into condicional.
0
 
LVL 3

Expert Comment

by:icarey
ID: 22981356
Aslam
working code below
A couple of notes:
1. I don't know what is in $_POST['******'] so I removed when I was testing.
2. During testing I also removed <? session_start();?>
3. I assumed that there is a page where you enter the value of ls_cut you wish to display, this page is then submitted and passes the ls_cut variable.
4. I have included my test page where you enter the value of ls_cut you want to display
5. If I am wrong in these assumptions then I will need for info

Ivan
Test calling page
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
<head>
<title>pagination.html</title>
</head>
<body>
 
<form action="pagination3.php" method="POST">
<input type="text" name="ls_cut" value=""/>
<br />
<input type="submit" name="submin" value="Submit" />
</form>
 
</body>
</html>
 
*****************************************************
 
<? session_start();?>
 
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></HEAD>
<style type="text/css">
<!--
.style1 {
	color: #0000CC;
	font-weight: bold;
}
body {
	background-color: #CCCCCC;
}
.style2 {font-size: medium}
.style3 {
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style5 {
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
}
.style7 {
	font-size: 12px;
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
-->
</style>
 
<title>*******</title>
<BODY>
<table width="500" border="0" align="center">
  <tr>
    <td><div align="center" class="style1">
      <h2 class="style2 style3"></h2> 
    </div></td>
  </tr>
</table>
<p>
  <?php
if (isset($_POST['******'])) {
 
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("expertexchange") or die(mysql_error());
 
$limit = 3;
 
	// simpler to write like this
	$ls_cut = $_REQUEST["ls_cut"];
 
	$sql1 = "SELECT * FROM ls WHERE ls_cut = '$ls_cut'";
    $result_count = mysql_query($sql1);
    $totalrows = mysql_num_rows($result_count);
	
	echo $totalrows;
	
	// must reference $_GET["page"] as it will be sent from the page links
    if(empty($_GET["page"]))
	{ 
        // first time page is viewed
		$page = 1;
	}
	else
	{
		//value sent by the page links
		$page = $_GET["page"];
    } 
 
	// small change here
	$limitvalue = ($page * $limit) - $limit;  
        
 
// simplified here the sql statement
 $query = "SELECT * FROM ls WHERE ls_cut = '$ls_cut' LIMIT $limitvalue, $limit";
                
$result = mysql_query($query)
    or die (mysql_error());
$num_results = mysql_num_rows($result);
 
if($num_results == 0) {
        echo "<table border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:16px;'>";
        echo "<tr><td>";
        echo "There are no records to display with reference to your search!";
        echo "</tr></td>";
        echo "</table>";
} else{
        echo "<table border='5' align='center' cellpadding='2' cellspacing='1' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'>";
        //      echo "<table align=center bgcolor=#FF9900 border='1'>";
         
  while($row = mysql_fetch_array($result)) {
 
		echo "<tr> <th>ParcelNo</th> <th>Type</th>  <th>Cut</th> <th>Clarity<br>From</th><th>Clarity<br>To</th> <th>Colour<br>From</th> <th>Colour<br>To</th><th>Plus</th> <th>Minus</th><th>MM X</th><th>MM</th></tr>";
		echo "<tr><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_parcel_no'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_type'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_cut'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_clarity_from'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_clarity_to'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_colour_from'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_colour_to'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sieve_size'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sieve_size_max'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mm'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mm_to'];
		echo "</td>";
		echo "</tr><br><tr>";
		echo "<th>Table %</th><th>Total<br>Depth</th> <th>Crown<br>Angle</th><th>Crown<br>Height</th><th>Pav<br>Depth</th>  <th>Pav<br>Angle</th><th>Girdle</th>  <th>Culet</th></tr><tr>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['percent_table'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['total_depth'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['crown_angle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['crown_ht'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['pav_depth'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['pav_angle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['girdle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['culet'];
		echo "</td></tr><tr>";
		echo "<th>mment</th><th>Cut<br>Grade</th> <th>Polish<br>Grade</th><th>Symm</th><th>Table</th>  <th>Cert</th><th>Flo</th>  <th>Total<br>Wt</th> <th>Total<br>Pcs</th>  <th>Edit</th> <th>Delete</th></tr><tr>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mment'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['cut_grade'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['polish_grade'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sym'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['dia_table'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['cert'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['flo'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>";
		echo $row['ls_total_wt'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_total_pcs'];
		echo "<td bgcolor='#FFFFFF'>"; 
		echo "<a href=editfile.php?id=";
		echo $row['ls_id'];
		echo ">Edit</a>";
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo "<a onclick=\"return confirm('Are you sure you want to delete this parcel?');\" href=\"some.php?id=";
		echo $row['id'];
		echo "\">Delete</a>";
		echo "</td>";
		echo "</tr>";
		echo "<tr><td colspan='11' bgcolor='#333333'>&nbsp;</td>";
		echo "</tr>";
	}
	
	    echo "</table>";
	}	
	}
		echo "<table  align='center'>";
        echo "<tr><td  align='center'><p align=center>";
												
												// added ls_cut=$ls_cut here to the link so that it gets sent back to the sql's above
                                                if($page != 1) {  
                                                                $pageprev = $page - 1; 
                                                                                                                        
																echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$ls_cut&page=" . $pageprev . "\">PREV " . $limit  . "</a>   ");  
                                                        } else { 
                                                                echo("PREV " . $limit . "   "); 
                                                        } 
 
                                                        $numofpages = $totalrows / $limit;  
                                                         
                                                        for($i = 1; $i <= $numofpages; $i++) { 
                                                                if($i == $page) { 
                                                                        echo($i . " "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$ls_cut&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
 
                                                        if(($totalrows % $limit) != 0) { 
                                                                if($i == $page) { 
                                                                        echo($i." "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$ls_cut&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
                                                        if(($totalrows - ($limit * $page)) > 0) { 
                                                                $pagenext = $page + 1; 
                                                                echo("  <a href=\"$_SERVER[PHP_SELF]?ls_cut=$ls_cut&page=" . $pagenext . "\">NEXT " . $limit . "</a>");  
                                                        } else { 
                                                                echo("  NEXT " . $limit);  
                                                        }                                       
                                                                
                
                echo "</p></td></tr>";
                echo "</table>";
				
				//below for debugging only uncomment to see php variables
				//phpinfo();
 
?></p>
 
</BODY>
</HTML>
 
 

Open in new window

0
 

Author Comment

by:786aslamkhan
ID: 22986241
Ivan
Thanks for the working code- I tried it-same problem- Links don't work. What could be wrong on my side? i've sent you the whole code. I cannot understand how it works at your end and not at mine!
Sorry man I'm sure doing something wrong.....
Aslam

0
 

Author Comment

by:786aslamkhan
ID: 22986263
Aroldus thanks for looking and trying to help..... examples are like "Round", "Square", "Octagon" etc.
0
 

Expert Comment

by:aroldus
ID: 22986576
Do you read what I said about the $_POST? When you click on a link you don't send POST data, only GET parameters so you never go into if($_POST[****]) coming from a link. Aslamkhan erased it too.
You have to think about another boolean to evaluate like $_REQUEST[****] and send like GET data, or save it into $_SESSION...
0
 

Author Comment

by:786aslamkhan
ID: 22987795
Aroldus Hi! you are so right about the $_POST if its coming from a link. However in this case, it comes from a button (submit) so there is no need to wory. thanks ;)
0
 

Expert Comment

by:aroldus
ID: 22988019
It comes from a form (with post data) the first time.
At these time when you get the page with data table and its pagination, you click on pagination link and go to the same page without post data.
I'm sorry to be annoying but I don't think it's going to work without erasing its conditional.

Try it please:
<? session_start();?>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></HEAD>
<style type="text/css">
<!--
.style1 {
	color: #0000CC;
	font-weight: bold;
}
body {
	background-color: #CCCCCC;
}
.style2 {font-size: medium}
.style3 {
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style5 {
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
}
.style7 {
	font-size: 12px;
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
-->
</style>
 
<title>*******</title>
<BODY>
<table width="500" border="0" align="center">
  <tr>
    <td><div align="center" class="style1">
      <h2 class="style2 style3"></h2> 
    </div></td>
  </tr>
</table>
<p>
  <?php
if(isset($_POST['******']) $_SESSION['******'] = $_POST['******']; 
if (isset($_SESSION['******'])) {
 
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
 
$limit = 3;
 
	// simpler to write like this
	$fieldname = $_REQUEST["ls_cut"];
	$sql1 = "SELECT * FROM ls WHERE ls_cut = '$fieldname'";
    $result_count = mysql_query($sql1);
    $totalrows = mysql_num_rows($result_count);
	
	
	// must reference $_GET["page"] as it will be sent from the page links
    if(empty($_GET["page"]))
	{ 
        // first time page is viewed
		$page = 1;
	}
	else
	{
		//value sent by the page links
		$page = $_GET["page"];
    } 
 
	// small change here
	$limitvalue = ($page * $limit) - $limit;  
        
 
// simplified here the sql statement
 $query = "SELECT * FROM ls WHERE ls_cut = '$fieldname' LIMIT $limitvalue, $limit";
                
$result = mysql_query($query)
    or die (mysql_error());
$num_results = mysql_num_rows($result);
 
if($num_results == 0) {
        echo "<table border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:16px;'>";
        echo "<tr><td>";
        echo "There are no records to display with reference to your search!";
        echo "</tr></td>";
        echo "</table>";
} else{
        echo "<table border='5' align='center' cellpadding='2' cellspacing='1' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'>";
        //      echo "<table align=center bgcolor=#FF9900 border='1'>";
         
  while($row = mysql_fetch_array($result)) {
 
		echo "<tr> <th>ParcelNo</th> <th>Type</th>  <th>Cut</th> <th>Clarity<br>From</th><th>Clarity<br>To</th> <th>Colour<br>From</th> <th>Colour<br>To</th><th>Plus</th> <th>Minus</th><th>MM X</th><th>MM</th></tr>";
		echo "<tr><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_parcel_no'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_type'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_cut'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_clarity_from'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_clarity_to'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_colour_from'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_colour_to'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sieve_size'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sieve_size_max'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mm'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mm_to'];
		echo "</td>";
		echo "</tr><br><tr>";
		echo "<th>Table %</th><th>Total<br>Depth</th> <th>Crown<br>Angle</th><th>Crown<br>Height</th><th>Pav<br>Depth</th>  <th>Pav<br>Angle</th><th>Girdle</th>  <th>Culet</th></tr><tr>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['percent_table'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['total_depth'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['crown_angle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['crown_ht'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['pav_depth'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['pav_angle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['girdle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['culet'];
		echo "</td></tr><tr>";
		echo "<th>mment</th><th>Cut<br>Grade</th> <th>Polish<br>Grade</th><th>Symm</th><th>Table</th>  <th>Cert</th><th>Flo</th>  <th>Total<br>Wt</th> <th>Total<br>Pcs</th>  <th>Edit</th> <th>Delete</th></tr><tr>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mment'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['cut_grade'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['polish_grade'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sym'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['dia_table'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['cert'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['flo'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>";
		echo $row['ls_total_wt'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_total_pcs'];
		echo "<td bgcolor='#FFFFFF'>"; 
		echo "<a href=editfile.php?id=";
		echo $row['ls_id'];
		echo ">Edit</a>";
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo "<a onclick=\"return confirm('Are you sure you want to delete this parcel?');\" href=\"some.php?id=";
		echo $row['id'];
		echo "\">Delete</a>";
		echo "</td>";
		echo "</tr>";
		echo "<tr><td colspan='11' bgcolor='#333333'>&nbsp;</td>";
		echo "</tr>";
	}
	
	    echo "</table>";
	}	
	}
		echo "<table  align='center'>";
        echo "<tr><td  align='center'><p align=center>";
												
												// added fieldname=$fieldname here to the link so that it gets sent back to the sql's above
                                                if($page != 1) {  
                                                                $pageprev = $page - 1; 
                                                                                                                        
																echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$fieldname&page=" . $pageprev . "\">PREV " . $limit  . "</a>   ");  
                                                        } else { 
                                                                echo("PREV " . $limit . "   "); 
                                                        } 
 
                                                        $numofpages = $totalrows / $limit;  
                                                         
                                                        for($i = 1; $i <= $numofpages; $i++) { 
                                                                if($i == $page) { 
                                                                        echo($i . " "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$fieldname&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
 
                                                        if(($totalrows % $limit) != 0) { 
                                                                if($i == $page) { 
                                                                        echo($i." "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$fieldname&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
                                                        if(($totalrows - ($limit * $page)) > 0) { 
                                                                $pagenext = $page + 1; 
                                                                echo("  <a href=\"$_SERVER[PHP_SELF]?ls_cut=$fieldname&page=" . $pagenext . "\">NEXT " . $limit . "</a>");  
                                                        } else { 
                                                                echo("  NEXT " . $limit);  
                                                        }                                       
                                                                
                
                echo "</p></td></tr>";
                echo "</table>";
				
				//below for debugging only uncomment to see php variables
				//phpinfo();
 
?></p>
 
</BODY>
</HTML>
 
 

Open in new window

0
 
LVL 3

Expert Comment

by:icarey
ID: 22989142
Aslam
This what I suggested about the $_POST['*****']

I have included my test calling page again below to give you an example:
I need to know what your code for the page you are sending the data from I suspect you are not sending ls_cut as a variable, see my code below.
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
<head>
<title>pagination.html</title>
</head>
<body>
 
<form action="pagination3.php" method="POST">
<input type="text" name="ls_cut" value=""/>
<br />
<input type="submit" name="submin" value="Submit" />
</form>
 
</body>
</html>

Ivan
0
 

Author Comment

by:786aslamkhan
ID: 22991740
Aroldus thanks- I wil try but I think that there is a syntax erroron line 45...
if(isset($_POST['******']) $_SESSION['******'] = $_POST['******']; One closing parenthesis is missing.... I don't know where to place it. Please could you do it for me so that I can try the code?
Another thing.... for the $_SESSION['******'] I'm putting the session_register("*******") value- hope that is correct.
Thanks!
0
 

Author Comment

by:786aslamkhan
ID: 22991763
<form name="form" method="post" action="xyz.php">
      <div align="right">
        <table border="5" align="left" cellpadding="1" cellspacing="1" bgcolor="#333333">
          <tr>
            <td><div align="right" class="style21">
              <div align="left">Cut </div>
            </div></td>
            <td><select name="ls_cut" id="ls_cut">
              <option value="">
                <?
              $query = "SELECT * FROM  cut";
                        $result = mysql_query($query);
                        while($record = mysql_fetch_assoc($result)) {
                              echo "<OPTION VALUE = '".$record['ls_cut']."'>".$record['ls_cut'];
                        }
                        ?>
                </option>
            </select></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input name="search" type="submit" id="search" value="Search" /></td>
          </tr>
        </table>
      </div>
    </form>
Ivan hi!
I have attached a code snippet of the "calling page" for you- please have a look.
Aslam.

Open in new window

0
 
LVL 3

Accepted Solution

by:
icarey earned 2000 total points
ID: 22992174
Hello Aslam
Main difference I made is in the main page
changed $ls_cut = $_POST["*******"];
to $ls_cut = $_REQUEST["ls_cut"];

both code attached below

Calling form
<?php
 
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
 
	
?>
 
 
 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
<head>
<title>select cut</title>
</head>
<body>
 
 
<form name="form" method="post" action="pagination3.php">
      <div align="right">
        <table border="5" align="left" cellpadding="1" cellspacing="1" bgcolor="#333333">
          <tr>
            <td><div align="right" class="style21">
              <div align="left">Cut </div>
            </div></td>
            <td><select name="ls_cut" id="ls_cut">
              <option value="">
                <?
              $query = "SELECT * FROM  cut";
                        $result = mysql_query($query);
                        while($record = mysql_fetch_assoc($result)) {
                              echo "<OPTION VALUE = '".$record['ls_cut']."'>".$record['ls_cut'];
                        }
                        ?>
                </option>
            </select></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input name="search" type="submit" id="search" value="Search" /></td>
          </tr>
        </table>
      </div>
    </form>
 
</body>
</html>
 
******************************
 
Main page
 
<? session_start();?>
 
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></HEAD>
<style type="text/css">
<!--
.style1 {
	color: #0000CC;
	font-weight: bold;
}
body {
	background-color: #CCCCCC;
}
.style2 {font-size: medium}
.style3 {
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style5 {
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
}
.style7 {
	font-size: 12px;
	color: #CCCCCC;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
-->
</style>
 
<title>*******</title>
<BODY>
<table width="500" border="0" align="center">
  <tr>
    <td><div align="center" class="style1">
      <h2 class="style2 style3"></h2> 
    </div></td>
  </tr>
</table>
<p>
  <?php
if (isset($_REQUEST['ls_cut'])) {
 
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databasemname") or die(mysql_error());
 
$limit = 3;
 
	// simpler to write like this
	$ls_cut = $_REQUEST["ls_cut"];
 
	$sql1 = "SELECT * FROM ls WHERE ls_cut = '$ls_cut'";
    $result_count = mysql_query($sql1);
    $totalrows = mysql_num_rows($result_count);
	
	
	// must reference $_GET["page"] as it will be sent from the page links
    if(empty($_GET["page"]))
	{ 
        // first time page is viewed
		$page = 1;
	}
	else
	{
		//value sent by the page links
		$page = $_GET["page"];
    } 
 
	// small change here
	$limitvalue = ($page * $limit) - $limit;  
        
 
// simplified here the sql statement
 $query = "SELECT * FROM ls WHERE ls_cut = '$ls_cut' LIMIT $limitvalue, $limit";
                
$result = mysql_query($query)
    or die (mysql_error());
$num_results = mysql_num_rows($result);
 
if($num_results == 0) {
        echo "<table border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:16px;'>";
        echo "<tr><td>";
        echo "There are no records to display with reference to your search!";
        echo "</tr></td>";
        echo "</table>";
} else{
        echo "<table border='5' align='center' cellpadding='2' cellspacing='1' bordercolor='#333333' bgcolor='#CCCCCC' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'>";
        //      echo "<table align=center bgcolor=#FF9900 border='1'>";
         
  while($row = mysql_fetch_array($result)) {
 
		echo "<tr> <th>ParcelNo</th> <th>Type</th>  <th>Cut</th> <th>Clarity<br>From</th><th>Clarity<br>To</th> <th>Colour<br>From</th> <th>Colour<br>To</th><th>Plus</th> <th>Minus</th><th>MM X</th><th>MM</th></tr>";
		echo "<tr><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_parcel_no'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_type'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_cut'];
		echo "</td><td bgcolor='#FFFFFF'>"; 
		echo $row['ls_clarity_from'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_clarity_to'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_colour_from'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_colour_to'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sieve_size'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sieve_size_max'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mm'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mm_to'];
		echo "</td>";
		echo "</tr><br><tr>";
		echo "<th>Table %</th><th>Total<br>Depth</th> <th>Crown<br>Angle</th><th>Crown<br>Height</th><th>Pav<br>Depth</th>  <th>Pav<br>Angle</th><th>Girdle</th>  <th>Culet</th></tr><tr>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['percent_table'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['total_depth'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['crown_angle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['crown_ht'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['pav_depth'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['pav_angle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['girdle'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['culet'];
		echo "</td></tr><tr>";
		echo "<th>mment</th><th>Cut<br>Grade</th> <th>Polish<br>Grade</th><th>Symm</th><th>Table</th>  <th>Cert</th><th>Flo</th>  <th>Total<br>Wt</th> <th>Total<br>Pcs</th>  <th>Edit</th> <th>Delete</th></tr><tr>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['mment'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['cut_grade'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['polish_grade'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['sym'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['dia_table'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['cert'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['flo'];
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>";
		echo $row['ls_total_wt'];
		echo "</td>"; 
		echo "<td bgcolor='#FFFFFF'>"; 
		echo $row['ls_total_pcs'];
		echo "<td bgcolor='#FFFFFF'>"; 
		echo "<a href=editfile.php?id=";
		echo $row['ls_id'];
		echo ">Edit</a>";
		echo "</td>";
		echo "<td bgcolor='#FFFFFF'>"; 
		echo "<a onclick=\"return confirm('Are you sure you want to delete this parcel?');\" href=\"some.php?id=";
		echo $row['id'];
		echo "\">Delete</a>";
		echo "</td>";
		echo "</tr>";
		echo "<tr><td colspan='11' bgcolor='#333333'>&nbsp;</td>";
		echo "</tr>";
	}
	
	    echo "</table>";
	}	
	}
		echo "<table  align='center'>";
        echo "<tr><td  align='center'><p align=center>";
												
												// added ls_cut=$ls_cut here to the link so that it gets sent back to the sql's above
                                                if($page != 1) {  
                                                                $pageprev = $page - 1; 
                                                                                                                        
																echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$ls_cut&page=" . $pageprev . "\">PREV " . $limit  . "</a>   ");  
                                                        } else { 
                                                                echo("PREV " . $limit . "   "); 
                                                        } 
 
                                                        $numofpages = $totalrows / $limit;  
                                                         
                                                        for($i = 1; $i <= $numofpages; $i++) { 
                                                                if($i == $page) { 
                                                                        echo($i . " "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$ls_cut&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
 
                                                        if(($totalrows % $limit) != 0) { 
                                                                if($i == $page) { 
                                                                        echo($i." "); 
                                                                } else { 
                                                                        echo("<a href=\"$_SERVER[PHP_SELF]?ls_cut=$ls_cut&page=" . $i . "\">" . $i . "</a> "); 
                                                                } 
                                                        } 
 
                                                        if(($totalrows - ($limit * $page)) > 0) { 
                                                                $pagenext = $page + 1; 
                                                                echo("  <a href=\"$_SERVER[PHP_SELF]?ls_cut=$ls_cut&page=" . $pagenext . "\">NEXT " . $limit . "</a>");  
                                                        } else { 
                                                                echo("  NEXT " . $limit);  
                                                        }                                       
                                                                
                
                echo "</p></td></tr>";
                echo "</table>";
				
				//below for debugging only uncomment to see php variables
				//phpinfo();
 
?></p>
 
</BODY>
</HTML>

Open in new window

0
 

Expert Comment

by:aroldus
ID: 22992198
You're right my bad ^^U.
if(isset($_POST['******'])) $_SESSION['******'] = $_POST['******'];

Otherwise Ivan's last comment solution it too, without sessions if you don't want to use it.
0
 

Author Closing Comment

by:786aslamkhan
ID: 31516292
Thanks Ivan for your help- It works!!!!!!!!!!!!!!!!!!! You have taught me something new today- and I thank you for you patience, persevearence, time through these days and the clear instructions which was a great learning experience for me.
0
 

Author Comment

by:786aslamkhan
ID: 22992563
aroldus thanks a ton for your help and guidance! I greatly appreciate your time and effort. Cheers!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

864 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