yandoo Posted February 27, 2008 Share Posted February 27, 2008 Hi there, i was hoping for a little help with regard to my php code please. I have drop down thats options determine (using javascript) how a record is ORDERBY.This then is posted to 2nd page that displays the records ORDERBY whatever option the user inputted...This worked fine... I then added pagnation to those results (on the 2nd page) to limit them to 10 records per page... Since i have added pagnation, i find Multiple copies or the Same Single record is displayed which is exaclty equal to the amount of records there are in the table!? If the records Orderby are different (Orderby ID, Type, Name) as selected in drop down, it will display ONLY 1st record in the table, but Multiple times??? It should and used to display all the records in a table and order them appropriately...???? ??? If any body could help me that would be greatly appreciated <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- InstanceEndEditable --> <SCRIPT language=JavaScript src="time.js"></SCRIPT> <script language="JavaScript"> <!-- function gotoLink(form) { var OptionIndex=form.ListBoxURL.selectedIndex; parent.location = form.ListBoxURL.options[OptionIndex].value;} //--> </script> <!-- </head> <body> ini_set('error_reporting',E_ALL); $currentPage = $_SERVER["PHP_SELF"]; if (isset($_GET['orderby'])) { $orderby= $_GET['orderby']; }else{ $orderby="AnimalID"; } //CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD ?> <?php $maxRows_test1 = 10; $pageNum_test1 = 0; if (isset($_GET['pageNum_test1'])) { $pageNum_test1 = $_GET['pageNum_test1']; } $startRow_test1 = $pageNum_test1 * $maxRows_test1; mysql_select_db($database_woodside, $woodside); $test= ("SELECT * FROM animal ORDER BY $orderby DESC"); $query_limit_test = sprintf("%s LIMIT %d, %d", $test, $startRow_test1, $maxRows_test1); $test1 = mysql_query($query_limit_test, $woodside) or die(mysql_error()); $result = mysql_query($test) or die(mysql_error()); $row_test = mysql_fetch_assoc($result); $totalRows_test = mysql_num_rows($result); $row_test1 = mysql_fetch_assoc($test1); if (isset($_GET['totalRows_test1'])) { $totalRows_test1 = $_GET['totalRows_test1']; } else { $all_test1 = mysql_query($test); $totalRows_test1 = mysql_num_rows($all_test1); } $totalPages_test1 = ceil($totalRows_test1/$maxRows_test1)-1; $queryString_test = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_test1") == false && stristr($param, "totalRows_test1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_test = "&" . htmlentities(implode("&", $newParams)); } } $queryString_test = sprintf("&totalRows_test1=%d%s", $totalRows_test1, $queryString_test); ?> <?php echo'<table width="500" border="1" >'; echo '<tr>'; echo '<td width="100"><strong>Animal ID</strong></td>'; echo'<td width="100"><strong>Animal Type</strong></td>'; echo'<td width="100"><strong>Name</strong></td>'; echo '<td width="100"><strong>Breed</strong></td>'; echo '<td width="100"><strong>Date</strong></td>'; echo '</tr>'; echo'<tr>'; echo '</table>';?> <?php do { ?> <span class="text"> <?php echo '<table width="500" border="1" >'; echo'<td width="100">'; echo $row_test['AnimalID']; echo'</td>'; echo'<td width="100">'; echo $row_test['AnimalTypeID']; echo'</td>'; echo'<td width="100">'; echo $row_test['Name']; echo'</td>'; echo'<td width="100">'; echo $row_test['BreedID']; echo'</td>'; echo'<td width="100">'; echo $row_test['Date']; echo'</td>'; echo'</tr>'; echo'</table>'; ?> </span> <?php } while ($row_test1 = mysql_fetch_assoc($test1)); ?> <table border="0" width="50%" align="center"> <tr> <td width="23%" align="center"><?php if ($pageNum_test1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_test1=%d%s", $currentPage, 0, $queryString_test); ?>">First</a> <?php } // Show if not first page ?> </td> <td width="31%" align="center"><?php if ($pageNum_test1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_test1=%d%s", $currentPage, max(0, $pageNum_test1 - 1), $queryString_test); ?>">Previous</a> <?php } // Show if not first page ?> </td> <td width="23%" align="center"><?php if ($pageNum_test1 < $totalPages_test1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_test1=%d%s", $currentPage, min($totalPages_test1, $pageNum_test1 + 1), $queryString_test); ?>">Next</a> <?php } // Show if not last page ?> </td> <td width="23%" align="center"><?php if ($pageNum_test1 < $totalPages_test1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_test1=%d%s", $currentPage, $totalPages_test1, $queryString_test); ?>">Last</a> <?php } // Show if not last page ?> </td> </tr> </table> <strong>Records <?php echo ($startRow_test1 + 1) ?> to <?php echo min($startRow_test1 + $maxRows_test1, $totalRows_test1) ?> of <?php echo $totalRows_test1 ?></strong> <!-- InstanceEndEditable --></td> </tr> </table> </body> <!-- InstanceEnd --></html> <?php mysql_free_result($user_conditional); mysql_free_result($result); mysql_free_result($test1); ?> Thank you Quote Link to comment Share on other sites More sharing options...
yandoo Posted February 27, 2008 Author Share Posted February 27, 2008 Hi, Well i magaged to fix it.. Had to change [coded]echo $row_test['AnimalID']; etc.... to echo $row_test1['AnimalID']; to all results... Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.