Jump to content

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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...