Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Miscellany
Sunday, July 9th, 2006 at 9:47:25pm MDT 

  1. mysql_select_db("tdd1984") or die("Problem selecting database");
  2. $type = mysql_real_escape_string ($_GET['type']);
  3. //pagination strts
  4. $limit = 25;
  5.  
  6. $sql = "SELECT itemId, userId, description, date, city, county, idNum, name, price, type COUNT FROM (items JOIN user ON items.userId=user.ID) LEFT JOIN images ON items.itemId=images.idNum";
  7. if (isset($_GET['type'])) { $sql .= " WHERE type='". mysql_real_escape_string($_GET['type'])."'"; }
  8. $sql .="GROUP BY itemId";
  9. $result_count = mysql_query($sql) or die ("MySQL Error: ".mysql_error());
  10. $numofrows = mysql_num_rows ($result_count);
  11.  
  12. //pagination total number of rows
  13. if(empty($page)){    // Checks if the $page variable is empty (not set)
  14.         $page = 1;      // If it is empty, we're on page 1
  15.     }
  16.  
  17.      $limitvalue = $page * $limit - ($limit);
  18.     // Ex: (2 * 25) - 25 = 25 <- data starts at 25
  19.  
  20. //pagination query2
  21. $sql1 = "SELECT itemId, userId, description, date, city, county, idNum, name, price, type FROM (items JOIN user ON items.userId=user.ID) LEFT JOIN images ON items.itemId=images.idNum LIMIT $limitvalue, $limit";
  22. if (isset($_GET['type'])) { $sql .= " WHERE type='". mysql_real_escape_string($_GET['type'])."'"; }
  23. $sql .="GROUP BY itemId";
  24. $result = mysql_query($sql1) or die("Error: " . mysql_error());
  25.  
  26. //pagination if statement if nothing is to be returned :)
  27. if(mysql_num_rows($result) == 0){
  28.         echo("Nothing to Display!");
  29.     }
  30.  
  31.  
  32.  
  33. echo "<TABLE width=\"25px\">\n";
  34. echo "<TR><TD colspan=\"2\"><img src=\"http://indianaclassifiedads.com/description.jpg\"></TD><TD><img src=\"http://indianaclassifiedads.com/price.jpg\"></TD><TD><img src=\"http://indianaclassifiedads.com/datesubmitted.jpg\"><td><img src=\"http://indianaclassifiedads.com/city.jpg\"></td><TD><img src=\"http://indianaclassifiedads.com/county.jpg\"></td></TD></TR>\n";
  35.  
  36. //pagination while loop
  37. while($row = mysql_fetch_array($result)){
  38. for($i = 0; $i < $numofrows; $i++) {
  39.  //get a row from our result set
  40. if($i % 2) { //this means if there is a remainder
  41. echo "<TR bgcolor=\"#FFFFCC\">\n";
  42. } else {
  43. echo "<TR bgcolor=\"white\">\n";
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  if($row['idNum'] == null)
  51. {
  52. echo "<td class=\"result-cell-border\">&nbsp</td>";
  53. }
  54. else
  55. {
  56. echo "<td><img src=\"http://indianaclassifiedads.com/pic.gif\"></td>";
  57. }
  58. echo "</td>";
  59. echo "<td align=\"left\" class=\"result-cell-border\">
  60. <span class=\"result-title\">
  61. <a href=\"contact.php?type-id=".$row['itemId']."&userid=".$row['userId']."\ class=\"result-title\"\">".$row['name']."</a>
  62. </span>
  63. <br />".$row['description']."</a>
  64. </td>
  65. <td align=\"center\" class=\"result-cell-border\">$".$row['price']."</TD>
  66. <TD align=\"center\" class=\"result-cell-border\">".$row['date']."</td>
  67. <td align=\"center\" class=\"result-cell-border\">".$row['city']."</td>
  68. <td align=\"center\" class=\"result-cell-border\">".$row['county']."</TD>\n";
  69. echo "</TR>\n";
  70. }
  71. }
  72. echo "</TABLE>\n";
  73.  
  74.  
  75. //pagination next button
  76. if($page != 1){
  77.         $pageprev = $page--;
  78.         // Fancy way of subtracting 1 from $page
  79.  
  80.         echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");
  81.         /* Tip: It is a good idea NOT to use $PHP_SELF in this link. It may work,
  82. but to be 99.9% sure that it will, be sure to use the actual name of the file
  83. this script will be running on. Also, the   adds a space to the end of
  84. PREV, and gives some room between the numbers. */
  85.     }else
  86.         echo("PREV".$limit." ");
  87.         // If we're on page 1, PREV is not a link
  88.  
  89.          $numofpages = $$numofrows / $limit;
  90.     /* We divide our total amount of rows (for example 102) by the limit (25). This
  91.  
  92. will yield 4.08, which we can round down to 4. In the next few lines, we'll
  93. create 4 pages, and then check to see if we have extra rows remaining for a 5th
  94. page. */
  95.  
  96.     for($i = 1; $i <= $numofpages; $i++){
  97.     /* This for loop will add 1 to $i at the end of each pass until $i is greater
  98. than $numofpages (4.08). */
  99.  
  100.         if($i == $page){
  101.             echo($i." ");
  102.         }else{
  103.             echo("<a href=\"$PHP_SELF&page=$i\">$i</a> ");
  104.         }
  105.  
  106.         /* This if statement will not make the current page number available in
  107. link form. It will, however, make all other pages available in link form. */
  108.     }   // This ends the for loop
  109.  
  110. if(($numofrows % $limit) != 0){
  111.     /* The above statement is the key to knowing if there are remainders, and it's
  112. all because of the %. In PHP, C++, and other languages, the % is known as a
  113. Modulus. It returns the remainder after dividing two numbers. If there is no
  114. remainder, it returns zero. In our example, it will return 0.8 */
  115.  
  116.         if($i == $page){
  117.             echo($i." ");
  118.         }else{
  119.             echo("<a href=\"$PHP_SELF&page=$i\">$i</a> ");
  120.         }
  121.         /* This is the exact statement that turns pages into link form that is used
  122.  
  123. above */
  124.     }   // Ends the if statement
  125.  
  126.  
  127.     if(($numofrows - ($limit * $page)) > 0){
  128.     /* This statement checks to see if there are more rows remaining, meaning there
  129. are pages in front of the current one. */
  130.  
  131.         $pagenext   = $page++;
  132.         // Fancy way of adding 1 to page
  133.  
  134.         echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
  135.         /* Since there are pages remaining, this outputs NEXT in link form. */
  136.     }else{
  137.         echo("NEXT".$limit);
  138.         /* If we're on the last page possible, NEXT will NOT be displayed in link
  139. form. */
  140.     }
  141.  
  142.  
  143.  
  144.  
  145. ?>
  146.  
  147. </body>
  148. </html>

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
fantasy-obligation