josuenerd Posted October 12, 2010 Share Posted October 12, 2010 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 https://forums.phpfreaks.com/topic/215736-how-do-i-add-pagination-every-30-entries/ Share on other sites More sharing options...
litebearer Posted October 12, 2010 Share Posted October 12, 2010 Might look here http://phpeasystep.com/phptu/29.html Link to comment https://forums.phpfreaks.com/topic/215736-how-do-i-add-pagination-every-30-entries/#findComment-1121608 Share on other sites More sharing options...
josuenerd Posted October 13, 2010 Author Share Posted October 13, 2010 Might look here http://phpeasystep.com/phptu/29.html 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 https://forums.phpfreaks.com/topic/215736-how-do-i-add-pagination-every-30-entries/#findComment-1121689 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.