Jump to content

[SOLVED] Adding Next and Prev Page to code that is already in place


$username

Recommended Posts

Hello everyone,

    I have code that I already had in place but my end user would like to have next page for the MYSQL display.

I have read the doc that is posted on this site.

 

I am having issues getting it to work.

 

Here is all my code with the next and prev page code applied.

 

<?php

if (isset($_COOKIE["user"]))

setcookie("user", ($_COOKIE["user"]), time()+600);


else
header("Location:cookerr.htm");
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<script type="text/javascript"> 
function confirmdelete() { 
return confirm("Are you sure you want to delete?");   
} 
</script> 

<?php
include 'dbopen.php';
include 'dbconnect.php';

// Here is the code that I am using for Next and Prev Page
$limit = 2;
$query_count = "SELECT count(ID) FROM store";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);

if(empty($page)){    // Checks if the $page variable is empty (not set)
        $page = 1;      // If it is empty, we're on page 1
    }

    $limitvalue = $page * $limit - ($limit); 
    // Ex: (2 * 25) - 25 = 25 <- data starts at 25
    
    $query  = "SELECT * FROM store LIMIT $limitvalue, $limit";        
    $result = mysql_query($query) or die("Error: " . mysql_error()); 
    // Selects all the data from table.
    // mysql_error() will print an error if one occurs.
    
    /* Tip: The MySQL LIMIT value syntax is as follows: 
    
    LIMIT $row_to_start_at, $how_many_rows_to_return 
    
    */ 

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

//End Of Code for the part of the Next and Prev Page





if(!isset($cmd)) {
?>
<?php
if (!isset($_POST['submit'])) {
?>
<link href="/admin/tools/css/admin_style.css" rel="stylesheet" type="text/css" />


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title> --- </title>
<style type="text/css">
<!--
body {
background-color: #ffffff;
background-image: url(../images/bg.png);
}

table, tr, td, div{



font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
color:#000000;
border-collapse: collapse;
}
A:link { color: #000000; text-decoration : none;}
A:visited { color: #000000; text-decoration : none;}
A:active { color: #000000; text-decoration: none;}
A:hover { color: red; text-decoration: none;font-weight:bold;}

.style3 {
font-size: 14px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style10 {font-size: 10; font-weight: bold; }
-->
</style></head>

  <div>
<table>
   <tr>
<td>
	<form action="show.php">  
  <input name="submit3" type="submit" value="Show Cases" /></td>
	</form>
<td>	<form action="write.php">  
  <input name="submit32" type="submit" value="Add New Case" /> </td>
	</form>
<td>	<form action="lobby.php">  
      <input name="submit33" type="submit" value="Main Page" /></td>
	</form>
<td>	<form action="logoff.php">
  <input name="submit2" type="submit" value="Log Off" /></td>
	</form>
</td>
  </tr>
</table>
  </div>
</form>


<col span="1" align="right">
<!--
<p>
<form method="POST" action="updateinfo.php">
<table>
<col span="1" align="right" row span="2">
<tr>
	<td><font color="black">Case ID to Update:</font></td>
	<td><input type="text" name="ID" ></td>

	<td><input type="submit" value="Submit"></td>

</tr>
<tr>
>-->
<!-- <img width="400" height="100" src="\testmidapslogo.jpg"> -->
</tr>
</table>
</form>
</p>
<p>
<form action="delete.php" onsubmit="return confirmdelete();">
Case ID to Delete: <input type="text" name="IDname">
<input type="submit" name="delete" value="Delete">
</form>
</p>

<?
} else {
$ID = $_POST['IDname'];

$query=("DELETE FROM store WHERE ID = '$ID'");
mysql_query($query)
or die(mysql_error());
echo "";

}
}
?>

<p>
</p>
</tr>
</table>
</form>
</p>
<table border="2" width="1800" rules="all" cellpadding="2" cellspacing="0" bordercolor="#000000" bgcolor="silver">
  <tr>
    <td><a href="./show.php?Ord=ID"><b><u>Case ID</u></b></td>
    <td><a href="./show.php?Ord=FirstName"><b><u>First Name</u></b></td>
    <td><a href="./show.php?Ord=LastName"><b><u>Last Name</u></b></td>
<td><a href="./show.php?Ord=AddressStreet"><b><u>Street</u></b></td>
<td><a href="./show.php?Ord=AddressCity"><b><u>City</u></b></td>
<td><a href="./show.php?Ord=AddressState"><b><u>State</u></b></td>
<td><a href="./show.php?Ord=AddressZip"><b><u>ZipCode</u></b></td>
<td><a href="./show.php?Ord=Paid"><b><u>Paid</u></b></td>
<td><b>Amount</b></td>
<td width="200"><b>Attempt 1</b></td>
<td><b>Attempt 2</b></td>
<td><b>Attempt 3</b></td>
<td><b>Attempt 4</b></td>
<td><b><a href="./show.php?Ord=OtherInfo"><u>Other Info</u></b></td>
<td><b><a href="./show.php?Ord=ServBy"><u>Served By</u></b></td>
<td><a href="./show.php?Ord=ClientName"><b><u>Client Name</u></b></td>
<td><a href="./show.php?Ord=County"><b><u>County Served</u></b></td>
<td><b>Serv Date</b></td>
  </tr>

<?php
$Ord = $_GET['Ord'];
if ($Ord == "") 
$Ord = 'ID';
else
$Ord = $_GET['Ord'];
$sql = "SELECT * FROM store ORDER BY `$Ord`"; 
$query = mysql_query($sql);


while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo("<td><a href=\"updateinfo.php?ID=" .  $row["ID"] . "\" title=\"".$row["ID"]."\">" . $row["ID"] .  "</a></td>"); 
//echo "<td>".$row['ID']."</td>";
echo "<td>".$row['FirstName']."</td>";
echo "<td>".$row['LastName']."</td>";
echo "<td>".$row['AddressStreet']."</td>";
echo "<td>".$row['AddressCity']."</td>";
echo "<td>".$row['AddressState']."</td>";
echo "<td>".$row['AddressZip']."</td>";
echo "<td>".$row['Paid']."</td>";
echo "<td>".$row['Amount']."</td>";
echo "<td>".$row['CaseNotes1']."</td>";
echo "<td>".$row['CaseNotes2']."</td>";
echo "<td>".$row['CaseNotes3']."</td>";
echo "<td>".$row['CaseNotes4']."</td>";
echo "<td>".$row['OtherInfo']."</td>";
echo "<td>".$row['ServBy']."</td>";
echo "<td>".$row['ClientName']."</td>";
echo "<td>".$row['County']."</td>";
echo "<td>".$row['ServDate']."</td>";
echo "</tr>";
}

?>

<?

//More code for the Next and Prev page
$bgcolor = "#E0E0E0"; // light gray
    /* Sets up one of the background colors. The color stated here will be 
displayed second */


   echo("<table>");
    // Just a simple table
    
    while($row = mysql_fetch_array($result)){
    /* This starts the loop (a while loop). What this does is returns a row of data 
    to the $row array. Each time the loop restarts, the next row of data is used. 
    So, each pass of the loop returns a different row of data. */
        
        // Start The Background Check
        if($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }
        /* Tip: The color you want to appear first on the list should be where the 
#FFFFFF is listed. What this script does is checks to see if #E0E0E0 was used 
last; if it was, then it'll use #FFFFFF. All you have to do is replace the 
colors of your choice. */ 

echo("<tr bgcolor=".$bgcolor.">n<td>");
    // Here we start table row & table data
    // Make sure your bgcolor is the $bgcolor variable
    
    echo($row["users"]);
    /* Tip: This is how we add the users field from our row. You can use any field 
from your row: all you do is include the field's name inbetween the array 
brackets. Ex: $row["field_name_here"] */
    
    echo("</td>n<td>");
    // Here we end the one section of table data, and start another.
    
    echo($row["usersID"]);
    // Prints the usersID field
    
    echo("</td>n</tr>");
    // Here we end the table data & table row
    
    } /* This closes the loop. Anything after this bracket will display after the 
data you've pulled from the database. */
    
    echo("</table>");
    /* While we're at it, let's close the table tag--we don't want other data 
inside this table */
     

    if($page != 1){ 
        $pageprev = $page--;
        // Fancy way of subtracting 1 from $page
        
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");  
        /* Tip: It is a good idea NOT to use $PHP_SELF in this link. It may work, 
but to be 99.9% sure that it will, be sure to use the actual name of the file 
this script will be running on. Also, the   adds a space to the end of 
PREV, and gives some room between the numbers. */
    }else
        echo("PREV".$limit." "); 
        // If we're on page 1, PREV is not a link 



    $numofpages = $totalrows / $limit; 
    /* We divide our total amount of rows (for example 102) by the limit (25). This 

will yield 4.08, which we can round down to 4. In the next few lines, we'll 
create 4 pages, and then check to see if we have extra rows remaining for a 5th 
page. */
    
    for($i = 1; $i <= $numofpages; $i++){
    /* This for loop will add 1 to $i at the end of each pass until $i is greater 
than $numofpages (4.08). */
    
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF&page=$i\">$i</a> "); 
        }
        
        /* This if statement will not make the current page number available in 
link form. It will, however, make all other pages available in link form. */
    }   // This ends the for loop 
if(($totalrows % $limit) != 0){
    /* The above statement is the key to knowing if there are remainders, and it's 
all because of the %. In PHP, C++, and other languages, the % is known as a 
Modulus. It returns the remainder after dividing two numbers. If there is no 
remainder, it returns zero. In our example, it will return 0.8 */
     
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF&page=$i\">$i</a> ");
        }
        /* This is the exact statement that turns pages into link form that is used 

above */ 
    }   // Ends the if statement
     

  if(($totalrows - ($limit * $page)) > 0){
    /* This statement checks to see if there are more rows remaining, meaning there 
are pages in front of the current one. */
    
        $pagenext   = $page++;
        // Fancy way of adding 1 to page
         
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
        /* Since there are pages remaining, this outputs NEXT in link form. */ 
    }else{
        echo("NEXT".$limit); 
        /* If we're on the last page possible, NEXT will NOT be displayed in link 
form. */
    }
    
    mysql_free_result($result);
    /* This line is not required, since MySQL will free the result after all 
scripts have finished executing; however, it's a nice little backup. */
    
    // The next line tells the server to stop parsing PHP 

//End of more code for Next and Prev

?>
</table>
</body>
</html>

 

If there is any light that you can shine on this for me that would be great.

 

Thanks,

Brett

 

P.S. What is the tag to show HTMl and PHP code with all the nice colors.

 

 

Link to comment
Share on other sites

$query_count = "SELECT count(ID) FROM store";
$result_count = mysql_query($query_count);
$totalrows = $result_count[0];

 

num_rows would only return 1 as that is all you are requesting. That will get you the correct amount of rows.

Link to comment
Share on other sites

The issue I am having it is not working for the pages to show.

 

here is a screen Shot.

 

NextPageIssue.JPG

 

I don't know if I have the code Correctly. Or if I may have to setup something with the code that I have in place.

 

<?php

if (isset($_COOKIE["user"]))

setcookie("user", ($_COOKIE["user"]), time()+600);


else
header("Location:cookerr.htm");
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<script type="text/javascript"> 
function confirmdelete() { 
return confirm("Are you sure you want to delete?");   
} 
</script> 

<?php
include 'dbopen.php';
include 'dbconnect.php';


$limit = 2;
$query_count = "SELECT count(ID) FROM store";
$result_count = mysql_query($query_count);
$totalrows = $result_count[0];

if(empty($page)){    // Checks if the $page variable is empty (not set)
        $page = 1;      // If it is empty, we're on page 1
    }

    $limitvalue = $page * $limit - ($limit); 
    // Ex: (2 * 25) - 25 = 25 <- data starts at 25
    
    $query  = "SELECT * FROM store LIMIT $limitvalue, $limit";        
    $result = mysql_query($query) or die("Error: " . mysql_error()); 
    // Selects all the data from table.
    // mysql_error() will print an error if one occurs.
    
    /* Tip: The MySQL LIMIT value syntax is as follows: 
    
    LIMIT $row_to_start_at, $how_many_rows_to_return 
    
    */ 

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








if(!isset($cmd)) {
?>
<?php
if (!isset($_POST['submit'])) {
?>
<link href="/midaps/admin/tools/css/admin_style.css" rel="stylesheet" type="text/css" />


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title> --- </title>
<style type="text/css">
<!--
body {
background-color: #ffffff;
background-image: url(../images/bg.png);
}

table, tr, td, div{



font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
color:#000000;
border-collapse: collapse;
}
A:link { color: #000000; text-decoration : none;}
A:visited { color: #000000; text-decoration : none;}
A:active { color: #000000; text-decoration: none;}
A:hover { color: red; text-decoration: none;font-weight:bold;}

.style3 {
font-size: 14px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style10 {font-size: 10; font-weight: bold; }
-->
</style></head>

  <div>
<table>
   <tr>
<td>
	<form action="show.php">  
  <input name="submit3" type="submit" value="Show Cases" /></td>
	</form>
<td>	<form action="write.php">  
  <input name="submit32" type="submit" value="Add New Case" /> </td>
	</form>
<td>	<form action="lobby.php">  
      <input name="submit33" type="submit" value="Main Page" /></td>
	</form>
<td>	<form action="logoff.php">
  <input name="submit2" type="submit" value="Log Off" /></td>
	</form>
</td>
  </tr>
</table>
  </div>
</form>


<col span="1" align="right">
<!--
<p>
<form method="POST" action="updateinfo.php">
<table>
<col span="1" align="right" row span="2">
<tr>
	<td><font color="black">Case ID to Update:</font></td>
	<td><input type="text" name="ID" ></td>

	<td><input type="submit" value="Submit"></td>

</tr>
<tr>
>-->
<!-- <img width="400" height="100" src="\testmidapslogo.jpg"> -->
</tr>
</table>
</form>
</p>
<p>
<form action="delete.php" onsubmit="return confirmdelete();">
Case ID to Delete: <input type="text" name="IDname">
<input type="submit" name="delete" value="Delete">
</form>
</p>

<?
} else {
$ID = $_POST['IDname'];

$query=("DELETE FROM store WHERE ID = '$ID'");
mysql_query($query)
or die(mysql_error());
echo "";

}
}
?>

<p>
</p>
</tr>
</table>
</form>
</p>
<table border="2" width="1800" rules="all" cellpadding="2" cellspacing="0" bordercolor="#000000" bgcolor="silver">
  <tr>
    <td><a href="./show.php?Ord=ID"><b><u>Case ID</u></b></td>
    <td><a href="./show.php?Ord=FirstName"><b><u>First Name</u></b></td>
    <td><a href="./show.php?Ord=LastName"><b><u>Last Name</u></b></td>
<td><a href="./show.php?Ord=AddressStreet"><b><u>Street</u></b></td>
<td><a href="./show.php?Ord=AddressCity"><b><u>City</u></b></td>
<td><a href="./show.php?Ord=AddressState"><b><u>State</u></b></td>
<td><a href="./show.php?Ord=AddressZip"><b><u>ZipCode</u></b></td>
<td><a href="./show.php?Ord=Paid"><b><u>Paid</u></b></td>
<td><b>Amount</b></td>
<td width="200"><b>Attempt 1</b></td>
<td><b>Attempt 2</b></td>
<td><b>Attempt 3</b></td>
<td><b>Attempt 4</b></td>
<td><b><a href="./show.php?Ord=OtherInfo"><u>Other Info</u></b></td>
<td><b><a href="./show.php?Ord=ServBy"><u>Served By</u></b></td>
<td><a href="./show.php?Ord=ClientName"><b><u>Client Name</u></b></td>
<td><a href="./show.php?Ord=County"><b><u>County Served</u></b></td>
<td><b>Serv Date</b></td>
  </tr>

<?php
$Ord = $_GET['Ord'];
if ($Ord == "") 
$Ord = 'ID';
else
$Ord = $_GET['Ord'];
$sql = "SELECT * FROM store ORDER BY `$Ord`"; 
$query = mysql_query($sql);


while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo("<td><a href=\"updateinfo.php?ID=" .  $row["ID"] . "\" title=\"".$row["ID"]."\">" . $row["ID"] .  "</a></td>"); 
//echo "<td>".$row['ID']."</td>";
echo "<td>".$row['FirstName']."</td>";
echo "<td>".$row['LastName']."</td>";
echo "<td>".$row['AddressStreet']."</td>";
echo "<td>".$row['AddressCity']."</td>";
echo "<td>".$row['AddressState']."</td>";
echo "<td>".$row['AddressZip']."</td>";
echo "<td>".$row['Paid']."</td>";
echo "<td>".$row['Amount']."</td>";
echo "<td>".$row['CaseNotes1']."</td>";
echo "<td>".$row['CaseNotes2']."</td>";
echo "<td>".$row['CaseNotes3']."</td>";
echo "<td>".$row['CaseNotes4']."</td>";
echo "<td>".$row['OtherInfo']."</td>";
echo "<td>".$row['ServBy']."</td>";
echo "<td>".$row['ClientName']."</td>";
echo "<td>".$row['County']."</td>";
echo "<td>".$row['ServDate']."</td>";
echo "</tr>";
}

?>

<?
$bgcolor = "#E0E0E0"; // light gray
    /* Sets up one of the background colors. The color stated here will be 
displayed second */

    echo("<table>");
    // Just a simple table
    
    while($row = mysql_fetch_array($result)){
    /* This starts the loop (a while loop). What this does is returns a row of data 
    to the $row array. Each time the loop restarts, the next row of data is used. 
    So, each pass of the loop returns a different row of data. */
        
        // Start The Background Check
        if($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }
        /* Tip: The color you want to appear first on the list should be where the 
#FFFFFF is listed. What this script does is checks to see if #E0E0E0 was used 
last; if it was, then it'll use #FFFFFF. All you have to do is replace the 
colors of your choice. */ 

echo("<tr bgcolor=".$bgcolor.">n<td>");
    // Here we start table row & table data
    // Make sure your bgcolor is the $bgcolor variable
    
    echo($row["users"]);
    /* Tip: This is how we add the users field from our row. You can use any field 
from your row: all you do is include the field's name inbetween the array 
brackets. Ex: $row["field_name_here"] */
    
    echo("</td>n<td>");
    // Here we end the one section of table data, and start another.
    
    echo($row["usersID"]);
    // Prints the usersID field
    
    echo("</td>n</tr>");
    // Here we end the table data & table row
    
    } /* This closes the loop. Anything after this bracket will display after the 
data you've pulled from the database. */
    
    echo("</table>");
    /* While we're at it, let's close the table tag--we don't want other data 
inside this table */
     

    if($page != 1){ 
        $pageprev = $page--;
        // Fancy way of subtracting 1 from $page
        
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");  
        /* Tip: It is a good idea NOT to use $PHP_SELF in this link. It may work, 
but to be 99.9% sure that it will, be sure to use the actual name of the file 
this script will be running on. Also, the   adds a space to the end of 
PREV, and gives some room between the numbers. */
    }else
        echo("PREV".$limit." "); 
        // If we're on page 1, PREV is not a link 



    $numofpages = $totalrows / $limit; 
    /* We divide our total amount of rows (for example 102) by the limit (25). This 

will yield 4.08, which we can round down to 4. In the next few lines, we'll 
create 4 pages, and then check to see if we have extra rows remaining for a 5th 
page. */
    
    for($i = 1; $i <= $numofpages; $i++){
    /* This for loop will add 1 to $i at the end of each pass until $i is greater 
than $numofpages (4.08). */
    
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF&page=$i\">$i</a> "); 
        }
        
        /* This if statement will not make the current page number available in 
link form. It will, however, make all other pages available in link form. */
    }   // This ends the for loop 
if(($totalrows % $limit) != 0){
    /* The above statement is the key to knowing if there are remainders, and it's 
all because of the %. In PHP, C++, and other languages, the % is known as a 
Modulus. It returns the remainder after dividing two numbers. If there is no 
remainder, it returns zero. In our example, it will return 0.8 */
     
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF&page=$i\">$i</a> ");
        }
        /* This is the exact statement that turns pages into link form that is used 

above */ 
    }   // Ends the if statement
     

  if(($totalrows - ($limit * $page)) > 0){
    /* This statement checks to see if there are more rows remaining, meaning there 
are pages in front of the current one. */
    
        $pagenext   = $page++;
        // Fancy way of adding 1 to page
         
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
        /* Since there are pages remaining, this outputs NEXT in link form. */ 
    }else{
        echo("NEXT".$limit); 
        /* If we're on the last page possible, NEXT will NOT be displayed in link 
form. */
    }
    
    mysql_free_result($result);
    /* This line is not required, since MySQL will free the result after all 
scripts have finished executing; however, it's a nice little backup. */
    
    // The next line tells the server to stop parsing PHP 



?>
</table>
</body>
</html>

 

Thanks,

Brett

Link to comment
Share on other sites

Thanks for your guys help. After looking into this one for some time I finally got it to work.

 

Here is the code for this.

 

<?php

if (isset($_COOKIE["user"]))

setcookie("user", ($_COOKIE["user"]), time()+600);


else
header("Location:cookerr.htm");
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<script type="text/javascript"> 
function confirmdelete() { 
return confirm("Are you sure you want to delete?");   
} 
</script> 

<?
if(!isset($cmd)) {
?>
<?php
if (!isset($_POST['submit'])) {
?>
<link href="/midaps/admin/tools/css/admin_style.css" rel="stylesheet" type="text/css" />


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title> --- </title>
<style type="text/css">
<!--
body {
background-color: #ffffff;
background-image: url(../images/bg.png);
}

table, tr, td, div{



font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
color:#000000;
border-collapse: collapse;
}
A:link { color: #000000; text-decoration : none;}
A:visited { color: #000000; text-decoration : none;}
A:active { color: #000000; text-decoration: none;}
A:hover { color: red; text-decoration: none;font-weight:bold;}

.style3 {
font-size: 14px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style10 {font-size: 10; font-weight: bold; }
-->
<p>
</style></head>

  <div>
<table>
   <tr>
<td>
	<form action="show.php">  
  <input name="submit3" type="submit" value="Show Cases" /></td>
	</form>
<td>	<form action="write.php">  
  <input name="submit32" type="submit" value="Add New Case" /> </td>
	</form>
<td>	<form action="lobby.php">  
      <input name="submit33" type="submit" value="Main Page" /></td>
	</form>
<td>	<form action="logoff.php">
  <input name="submit2" type="submit" value="Log Off" /></td>
	</form>
</td>
  </tr>
</table>
  </div>
</form>


<col span="1" align="right">
<!--
<p>
<form method="POST" action="updateinfo.php">
<table>
<col span="1" align="right" row span="2">
<tr>
	<td><font color="black">Case ID to Update:</font></td>
	<td><input type="text" name="ID" ></td>

	<td><input type="submit" value="Submit"></td>

</tr>
<tr>
>-->
<!-- <img width="400" height="100" src="\testmidapslogo.jpg"> -->
</tr>
</table>
</form>
</p>
<p>
<form action="delete.php" onsubmit="return confirmdelete();">
Case ID to Delete: <input type="text" name="IDname">
<input type="submit" name="delete" value="Delete">
</form>
</p>

<?
} else {
$ID = $_POST['IDname'];

$query=("DELETE FROM store WHERE ID = '$ID'");
mysql_query($query)
or die(mysql_error());
echo "";

}
}
?>

</p>
</tr>
</table>
</form>
</p>
<table border="2" width="1800" rules="all" cellpadding="2" cellspacing="0" bordercolor="#000000" bgcolor="silver">
  <tr>
    <td><a href="./show.php?Ord=ID"><b><u>Case ID</u></b></td>
    <td><a href="./show.php?Ord=FirstName"><b><u>First Name</u></b></td>
    <td><a href="./show.php?Ord=LastName"><b><u>Last Name</u></b></td>
<td><a href="./show.php?Ord=AddressStreet"><b><u>Street</u></b></td>
<td><a href="./show.php?Ord=AddressCity"><b><u>City</u></b></td>
<td><a href="./show.php?Ord=AddressState"><b><u>State</u></b></td>
<td><a href="./show.php?Ord=AddressZip"><b><u>ZipCode</u></b></td>
<td><a href="./show.php?Ord=Paid"><b><u>Paid</u></b></td>
<td><b>Amount</b></td>
<td width="200"><b>Attempt 1</b></td>
<td><b>Attempt 2</b></td>
<td><b>Attempt 3</b></td>
<td><b>Attempt 4</b></td>
<td><b><a href="./show.php?Ord=OtherInfo"><u>Other Info</u></b></td>
<td><b><a href="./show.php?Ord=ServBy"><u>Served By</u></b></td>
<td><a href="./show.php?Ord=ClientName"><b><u>Client Name</u></b></td>
<td><a href="./show.php?Ord=County"><b><u>County Served</u></b></td>
<td><b>Serv Date</b></td>
  </tr>

<?php

include 'dbopen.php';
include 'dbconnect.php';
$rowsPerPage = 3;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$Ord = $_GET['Ord'];
if ($Ord == "") 
$Ord = 'ID';
else
$Ord = $_GET['Ord'];
$sql = "SELECT * FROM store ORDER BY `$Ord`"; 
//$query = mysql_query($sql);

$query = " SELECT * FROM store " .
         " LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');

// print the random numbers
while($row = mysql_fetch_array($result))
{
   //echo $row['ID'] . '<br>';
   echo "<tr>";
echo("<td><a href=\"updateinfo.php?ID=" .  $row["ID"] . "\" title=\"".$row["ID"]."\">" . $row["ID"] .  "</a></td>"); 
//echo "<td>".$row['ID']."</td>";
echo "<td>".$row['FirstName']."</td>";
echo "<td>".$row['LastName']."</td>";
echo "<td>".$row['AddressStreet']."</td>";
echo "<td>".$row['AddressCity']."</td>";
echo "<td>".$row['AddressState']."</td>";
echo "<td>".$row['AddressZip']."</td>";
echo "<td>".$row['Paid']."</td>";
echo "<td>".$row['Amount']."</td>";
echo "<td>".$row['CaseNotes1']."</td>";
echo "<td>".$row['CaseNotes2']."</td>";
echo "<td>".$row['CaseNotes3']."</td>";
echo "<td>".$row['CaseNotes4']."</td>";
echo "<td>".$row['OtherInfo']."</td>";
echo "<td>".$row['ServBy']."</td>";
echo "<td>".$row['ClientName']."</td>";
echo "<td>".$row['County']."</td>";
echo "<td>".$row['ServDate']."</td>";
echo "</tr>";
}


// ... more code here
// ... the previous code

// how many rows we have in database
$query   = "SELECT COUNT(ID) AS numrows FROM store";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav  = '';

for($page = 1; $page <= $maxPage; $page++)
{
   if ($page == $pageNum)
   {
      $nav .= " $page "; // no need to create a link to current page
   }
   else
   {
      $nav .= " <a href=\"$self?page=$page\">$page</a> ";
   }
}

// ... still more code coming
// creating previous and next link
// plus the link to go straight to
// the first and last page

if ($pageNum > 1)
{
   $page  = $pageNum - 1;
   $prev  = " <a href=\"$self?page=$page\">[Prev]</a> ";

   $first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
   $prev  = ' '; // we're on page one, don't print previous link
   $first = ' '; // nor the first page link
}

if ($pageNum < $maxPage)
{
   $page = $pageNum + 1;
   $next = " <a href=\"$self?page=$page\">[Next]</a> ";

   $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
   $next = ' '; // we're on the last page, don't print next link
   $last = ' '; // nor the last page link
}

// print the navigation link
echo $first . $prev . $nav . $next . $last;

// and close the database connection


// ... and we're done!
?>

</table>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.