Hello!
I am trying to merge the code for pagination and search and need help to do it.
I dont know how to make results display like
1, 2,
3, 4; I want to have the results dispalyed in two columns.
Also, the pagination numbers, next and prev button doesn't appear.
Can somebody give me a hint on how to solve this problem?
Thanks!
I am trying to merge the code for pagination and search and need help to do it.
I dont know how to make results display like
1, 2,
3, 4; I want to have the results dispalyed in two columns.
Also, the pagination numbers, next and prev button doesn't appear.
PHP:
<h2>Results:</h2>
<?php
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=trim($_POST['searchterm']);
if (!$searchtype || !$searchterm) {
echo 'You have not entered search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc()){
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db = new mysqli('localhost', 'user', 'pass', 'db');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
//start
//max displayed per page
$per_page = 4;
//get start variable
$start = $_GET['start'];
//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM tablename"));
if (!$start)
$start = 0;
//display data
//end
$get = $query;
$query =("select * from tablename where $max".$searchtype." like '%".$searchterm."%' LIMIT $start, $per_page");
$result = $db->query($query);
$num_results = $result->num_rows;
echo "<p>Number of items found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<div class=iskalnikbg>";
echo "<p><strong>".($i+1).". Št. artikla: ";
echo htmlspecialchars(stripslashes($row['st_artikla']));
echo "</strong><br />Opis: ";
echo stripslashes($row['opis']);
echo "<br />Barva: ";
echo stripslashes($row['barva']);
echo "<br />Št.: ";
echo stripslashes($row['st.']);
echo "<br />Cena: €";
echo stripslashes($row['cena']);
echo "</div>";
echo "<div class=thumb_position>";
echo stripslashes($row['ozadje']);
echo "</div>";
echo "</p>";
}
//start
//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
echo "<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>";
//show prev button
if (!($start<=0))
echo "<a href=index.php?start=$prev>Prev</a> ";
//show page numbers
//set variable for first page
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if ($start!=$x)
echo " <a href='index.php?start=$x'>$i</a> ";
else
echo " <a href='index.php?start=$x'><b>$i</b></a> ";
$i++;
}
//show next button
if (!($start>=$record_count-$per_page))
echo " <a href='index.php?start=$next'>Next</a>";
//end
$result->free();
$db->close();
?>
Thanks!
Last edited: