Jump to content

How do I add pagination every 30 entries?


josuenerd

Recommended Posts

Below is the part of my code that creates the html table.  How do I add pagination every 30 entries?

 

 

 

$db = mysql_connect("localhost","trend_learnu","asdfasdf");
mysql_select_db("trend_learningdb",$db);

$result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC");

$table = '<table width="608" border="0" align="center" cellpadding="10" cellspacing="0">
  <tr>
    <td style="color:#fff;" width="207" bgcolor="#425d74"><strong>Firstname</strong></td>
    <td style="color:#fff;" width="204" bgcolor="#425d74"><strong>Lastname</strong></td>
    <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Date</strong></td>
<td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Weight</strong></td>
  </tr>';

while($row=mysql_fetch_array($result))
{
  $firstname = $row['Firstname'];
  $lastname = $row['Lastname'];
  $weight = $row['Weight'];
  $date = $row['Date'];

   $table.= '<tr>';
   $table.= '<td bgcolor="#e8f4ff">'.$firstname.'</td>';
   $table.= '<td bgcolor="#e8f4ff">'.$lastname.'</td>';
   $table.= '<td bgcolor="#e8f4ff">'.$date.'</td>';
   $table.= '<td bgcolor="#e0ffe6"><strong>'.$weight.'</strong></td>';
   $table.= '</tr>';
}
$table .= '</table>';

echo $table;



mysql_close($con)

Link to comment
Share on other sites

 

 

I tried to add the pagination for several hours (about 5) but I was not able to do it :(

 

If anyone can please help me add pagination I would greatly appreciate it. Below is the code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Weight Log</title>
<style type="text/css">
body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}
body {
    background-color: #EEEEEE;
}
</style>
</head>

<body>


<?php
$con = mysql_connect("localhost","trend_learnu","asdfasdf");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


// START OF VALIDATION
$errors = array(); // set the errors array to empty, by default
$fields = array(); // stores the field values
$success_message = "This is a success";

if (isset($_POST['submit']))
{
  // import the validation library
  require("validation.php");

  $rules = array(); // stores the validation rules

  // standard form fields
  $rules[] = "required,Weight,Please enter your weight.";


  $errors = validateFields($_POST, $rules);

  // if there were errors, re-populate the form fields
  if (!empty($errors))
  {  
    $fields = $_POST;
  }
  
  // no errors! redirect the user to the thankyou page (or whatever)
  else 
  {
    $message = "All fields have been validated successfully!";
// START OF VALIDATION      
      
mysql_select_db("trend_learningdb", $con);

$sql="INSERT INTO Peoples (Firstname, Lastname, Weight, Date)
VALUES
('$_POST[Firstname]','$_POST[Lastname]','$_POST[Weight]','$_POST[Date]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

    
// END OF VALIDATION
// To redirect to a "thankyou" page, you'd just do this:
// header("Location: thanks.php");
  }
}
// END OF VALIDATION

$db = mysql_connect("localhost","trend_learnu","asdfasdf");
mysql_select_db("trend_learningdb",$db);

$result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC");

$table = '<table width="608" border="0" align="center" cellpadding="10" cellspacing="0">
  <tr>
    <td style="color:#fff;" width="207" bgcolor="#425d74"><strong>Firstname</strong></td>
    <td style="color:#fff;" width="204" bgcolor="#425d74"><strong>Lastname</strong></td>
    <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Date</strong></td>
    <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Weight</strong></td>
  </tr>';

while($row=mysql_fetch_array($result))
{
  $firstname = $row['Firstname'];
  $lastname = $row['Lastname'];
  $weight = $row['Weight'];
  $date = $row['Date'];

   $table.= '<tr>';
   $table.= '<td bgcolor="#e8f4ff">'.$firstname.'</td>';
   $table.= '<td bgcolor="#e8f4ff">'.$lastname.'</td>';
   $table.= '<td bgcolor="#e8f4ff">'.$date.'</td>';
   $table.= '<td bgcolor="#e0ffe6"><strong>'.$weight.'</strong></td>';
   $table.= '</tr>';
}
$table .= '</table>';

echo $table;



mysql_close($con)


?> 







<?php
$today = date("F j, Y");
?> 

<?php


$goalweight = 140;


  
  
$losepounds = $weight - $goalweight;  //we multiply varaible a and b and store the value in c

echo $tablegoal;

echo '<table width="500" border="0" align="center" cellpadding="15" cellspacing="0">
  <tr>
    <td align="center">You need to lose <strong>';
    
echo $losepounds;

echo '</strong> pounds to reach your Goal Weight of <strong>';

echo $goalweight;

echo '</strong>.</td>
  </tr>
</table>';

?> 


<style type="text/css">
<!--
body,p,table,td,input,select {
  font-family: verdana, tahoma;
    font-size: 8pt;
  line-height: 14pt;
}
.demoTable {
  background-color: #efefef;
  width: 100%;
}
.title { font-family: arial; font-size: 16pt; }
.section { font-size: 11pt; color: #3366cc; }
.error {
  border: 1px solid red;
  background-color: #ffffee;
  color: #660000;
  width: 400px;
  padding: 5px;
}
.notify {
  border: 1px solid #336699;
  background-color: #ffffee;
  color: #336699;
  width: 400px;
  padding: 5px;
}
-->
</style>


<table cellspacing="0" width="600" align="center">
<tr>
  <td>
    
    <form action="" method="post">
    <input name="Date" type="hidden" value="<?php PRINT "$today"; ?>" />

    
    <?php
    
    // if $errors is not empty, the form must have failed one or more validation 
    // tests. Loop through each and display them on the page for the user
    if (!empty($errors))
    {
      echo "<div class='error' style='width:100%;'>Please fix the following errors:\n<ul>";
      foreach ($errors as $error)
        echo "<li>$error</li>\n";
    
      echo "</ul></div>"; 
    }
    
    if (!empty($message))
    {
      echo "<div class='notify' style='width:100%;'>$success_message</div>";
    }
    ?>
    
    
    <table class="demoTable">
    <tr>
      <td>Required field:</td>
        <td><input type="text" name="Weight" value="<?=$fields['Weight']?>" /></td>
    </tr>
    </table>
    <p><input type="submit" name="submit" value="SUBMIT" /></p>
    
    </form>

    <br />
    
  </td>
</tr>
</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.