我已经在我的网站中建立了一个搜索功能,并有一个分页。首先,我有一个错误,显示用户是否还没有输入或只输入一个字符。但是我只希望这个错误能够工作一次' go' / submit已被按下。
其次,页面计数显示但是我想在结果和页面计数之间留出几行间隔,这样我的用户就可以清楚地看到它。
我尝试过:<br>
<br />``echo "\n"
等
建立休息的唯一方法是,如果我把回声&#34;你好&#34;,这显然不是我想要的东西,但这是反复试验。
我已经包含了我的代码:
<?php
session_start();
include "includes/header.php";
include "includes/connect.php";
?>
<link rel="stylesheet" type="text/css" href="css/generalstyle.css">
<div id = "searchBar">
<form action="search.php" method="GET">
Search : <input type="text" size="30" name="search" />
<input type="submit" name = "submit" value ="GO"/>
</form>
</div><!--END SEARCH BAR-->
<?php
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(strlen($search)<=1)
echo "Search term too short";
else{
echo "<br><br>You searched for <b>$search</b> <hr size='1'></br>";
$fullrecords = "SELECT * FROM apps WHERE ApplicationName LIKE'%$search%' OR ApplicationDescription LIKE '%$search%';";
$fullresult = mysqli_query($conn, $fullrecords);
$foundnum = mysqli_num_rows($fullresult);
if ($foundnum==0)
echo "Sorry, there are no matching applications for <b>$search</b>.</br></br>1. Try more general words. For example: If you want to search for 'how to write notes'then use general keywords like 'notes' or 'write'.</br>2. Try different words with similar meaning.</br>3. Please check your spelling and try again.";
else{
echo "$foundnum results found !<p>";
$per_page = 9;
$start = $_GET['start'];
$max_pages = ceil($foundnum / $per_page);
if(!$start)
$start=0;
$getquery = mysqli_query($conn, "SELECT ApplicationID, ApplicationName, ApplicationDescription FROM apps WHERE ApplicationName LIKE '%$search%' OR ApplicationDescription LIKE '%$search%' LIMIT $start, $per_page;");
while($row = $getquery->fetch_object()){
$_GET['search']=$_POST['search'];
echo "<div class=\"col-6 col-sm-6 col-lg-4\">";
echo '<form method="post" action="cart_update.php">';
echo '<h2>'.$row->ApplicationName.'</h2>';
echo '<p>'.$row->ApplicationDescription.'</p>';
echo '<button class="add_to_cart">Add To Cart</button>';
echo '<input type="hidden" name="product_code" value="'.$row->ApplicationID.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form></div>';
}
}
//Pagination Starts
echo "<center>";
$prev = $start - $per_page;
$next = $start + $per_page;
$last = $max_pages - 1;
if($max_pages > 1){
//previous button
if (!($start<=0))
echo "<a href='search.php?search=$search&submit=Search+source+code&start=$prev'>Prev |</a> ";
//pages
$i = 0;
for ($counter = 1; $counter <= $max_pages; $counter++){
if($i == $start){
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b> $counter |</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'> $counter |</a> ";
}
$i = $i + $per_page;
}
}
//next button
if (!($start >=$foundnum-$per_page))
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$next'> Next</a> ";
}
echo "</center>";