Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //input information to SQL DB
- $username = "root";
- $password = "";
- $hostname = "localhost";
- $table = "ink";
- //connect to SQL DB
- $dbhandle = mysql_connect($hostname, $username, $password) or die("unable to connect to Database");
- echo "Connected to db<br>";
- //specify database we will be using to search
- mysql_select_db("ink") or die("unable to select database");
- //get the search variable
- $var = @$POST['q'];
- $trimmed = trim($var);
- //rows to return
- $limit=10;
- //check for an empty string
- if ($trimmed == "")
- {
- echo "<p>Please enter a search...</p>";
- exit;
- }
- //check for serch parameter
- if(!isset($var))
- {
- echo "<p>We don't seem to have a search parameter!<P>";
- exit;
- }
- //locate the sql query
- $query = "select * from ink where ink is \"%$trimmed%\" order by ink";
- $numresults = mysql_query($query,$dbhandle);
- $numrows = mysql_num_rows($rumresults);
- //no results
- if ($numrows == 0)
- {
- echo "<h4>Results</h4>";
- echo "<p>Sorry, your search: "" . $trimmed . "" retuned zero results</p>";
- }
- if (empty($s)){
- $s=0;
- }
- //get results
- $query .= " limit $s,$limit";
- $results = mysql_query($query) or die("Couldn't execute query");
- //display what was searched
- echo "<p>You searched for: "" . $var. ""l</p>";
- //begin to show results
- echo "results";
- $count = 1 + $s;
- //now we can display results returned
- while($row= mysql_fetch_array($result)) {
- $title = $row["ink"];
- echo "$count.)%nbsp;$title";
- $count++;
- }
- $currPage = (($s/$limit) + 1);
- // next we need to do the links to other results
- if ($s>=1) { // bypass PREV link if s is 0
- $prevs=($s-$limit);
- print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
- Prev 10</a>  ";
- }
- // calculate number of pages needing links
- $pages=intval($numrows/$limit);
- // $pages now contains int of pages needed unless there is a remainder from division
- if ($numrows%$limit) {
- // has remainder so add one page
- $pages++;
- }
- // check to see if last page
- if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
- // not last page so give NEXT link
- $news=$s+$limit;
- echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
- }
- $a = $s + ($limit) ;
- if ($a > $numrows) { $a = $numrows ; }
- $b = $s + 1 ;
- echo "<p>Showing results $b to $a of $numrows</p>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement