Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. //input information to SQL DB
  5. $username = "root";
  6. $password = "";
  7. $hostname = "localhost";
  8. $table = "ink";
  9.  
  10. //connect to SQL DB
  11. $dbhandle = mysql_connect($hostname, $username, $password) or die("unable to connect to Database");
  12. echo "Connected to db<br>";
  13.  
  14. //specify database we will be using to search
  15. mysql_select_db("ink") or die("unable to select database");
  16.  
  17.  
  18. //get the search variable
  19. $var = @$POST['q'];
  20. $trimmed = trim($var);
  21.  
  22. //rows to return
  23. $limit=10;
  24.  
  25. //check for an empty string
  26. if ($trimmed == "")
  27. {
  28. echo "<p>Please enter a search...</p>";
  29. exit;
  30. }
  31.  
  32. //check for serch parameter
  33. if(!isset($var))
  34. {
  35. echo "<p>We don't seem to have a search parameter!<P>";
  36. exit;
  37. }
  38.  
  39. //locate the sql query
  40. $query = "select * from ink where ink is \"%$trimmed%\" order by ink";
  41.  
  42. $numresults = mysql_query($query,$dbhandle);
  43. $numrows = mysql_num_rows($rumresults);
  44.  
  45. //no results
  46.  
  47. if ($numrows == 0)
  48. {
  49. echo "<h4>Results</h4>";
  50. echo "<p>Sorry, your search: "" . $trimmed . "" retuned zero results</p>";
  51. }
  52.  
  53. if (empty($s)){
  54. $s=0;
  55. }
  56.  
  57. //get results
  58. $query .= " limit $s,$limit";
  59. $results = mysql_query($query) or die("Couldn't execute query");
  60.  
  61. //display what was searched
  62. echo "<p>You searched for: "" . $var. "&quotl</p>";
  63.  
  64. //begin to show results
  65.  
  66. echo "results";
  67. $count = 1 + $s;
  68.  
  69. //now we can display results returned
  70.  
  71. while($row= mysql_fetch_array($result)) {
  72. $title = $row["ink"];
  73.  
  74. echo "$count.)%nbsp;$title";
  75. $count++;
  76. }
  77.  
  78. $currPage = (($s/$limit) + 1);
  79.  
  80.  
  81. // next we need to do the links to other results
  82. if ($s>=1) { // bypass PREV link if s is 0
  83. $prevs=($s-$limit);
  84. print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
  85. Prev 10</a>&nbsp&nbsp;";
  86. }
  87.  
  88. // calculate number of pages needing links
  89. $pages=intval($numrows/$limit);
  90.  
  91. // $pages now contains int of pages needed unless there is a remainder from division
  92.  
  93. if ($numrows%$limit) {
  94. // has remainder so add one page
  95. $pages++;
  96. }
  97.  
  98. // check to see if last page
  99. if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
  100.  
  101. // not last page so give NEXT link
  102. $news=$s+$limit;
  103.  
  104. echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
  105. }
  106.  
  107. $a = $s + ($limit) ;
  108. if ($a > $numrows) { $a = $numrows ; }
  109. $b = $s + 1 ;
  110. echo "<p>Showing results $b to $a of $numrows</p>";
  111.  
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement