Jump to content

etsted

Recommended Posts

i have to scripts i want to combine, but i am not sure how to, could someone show me?

 

search script:

 

<h1>Search:</h1>
<form action="search.php" method="get" class="search">
<input type="text" name="k" size='50' />
<input type="submit" name="submit" value='Search' />
</form>
<?php
$username = $_SESSION['username'];
if(isset($username))
{
include "navigator/navigator_login.php";
} else {
include "navigator/navigator.php";
}
?>
<hr />
<?php
// also check out facebook and twitter like buttons
include "connect.php";
$k = mysqli_real_escape_string($con, htmlentities(trim($_GET['k'])));
$terms = explode(" ", $k);
$query = "SELECT * FROM videos WHERE ";
$i = 0;
foreach($terms as $each) {
$i++;
if($i == 1) {
$query .= "description LIKE '%$each%' ";
} else {
$query .= "OR description LIKE '%$each%' ";
}
}
$result = mysqli_query($con, $query) or die(mysqli_error($con));
$numrows = mysqli_num_rows($result);
if($numrows > 0)
{
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$title = $row['title'];
$url = $row['url'];
$description = $row['description'];
if($k == "") {
echo "";
} else {
echo "<h3><a href='$url'>$title</a></h3>
$description";
}
}
} else {
echo "no results on $k";
}
mysqli_close($con);
pagination script:
include "connect.php";
$count_query = mysql_query("SELECT NULL FROM bruker");
$count = mysql_num_rows($count_query);
if(isset($_GET['page'])) {
$page = preg_replace("#[^0-9]#","",$_GET['page']);
} else {
$page = 1;
}
$perPage = 10;
$lastPage = ceil($count/$perPage);
if($page < 1) {
$page = 1;
} else {
if($page > $lastPage) {
$page = $lastPage;
}
}
$limit = "LIMIT " . ($page - 1) * $perPage . ", $perPage";
$query = mysql_query("SELECT name FROM bruker ORDER BY id DESC $limit");
if($lastPage != 1) {
if($page != $lastPage) {
$next = $page + 1;
$pagination .= '<a href="pagination.php?page='.$next.'">Next</a>';
}
if($page != 1) {
$prev = $page - 1;
$pagination .= '<a href="pagination.php?page='.$prev.'">Previous</a>';
}
}
while($row = mysql_fetch_array($query)) {
$output .= $row['name'] . "<br />";
}
echo $output;
echo $pagination;

 

Link to comment
Share on other sites

What are you having problems with? The pagination script shows how to determine which page you're on, how many items to show per page, and how to construct the LIMIT clause of the SL query to only get the records for that page. You should be able to add that same logic into your search script. The major difference is that your search script will need to still include the search keywords in the next and previous links.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...