PHP pagination if empty do nothing and formatting -
i have built search function site, pagination.firstly, have error show if user has not entered or has entered 1 character. want error work once 'go' /submit has been pressed.
secondly, page count displaying want few lines gap between results , page count, visually clear users.
i have tried:<br>
<br />``echo "\n"
etc. way establish break if put echo "hello
", isnt want obviously, trial , error.
i have included code:
<?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 short"; else{ echo "<br><br>you searched <b>$search</b> <hr size='1'></br>"; $fullrecords = "select * apps applicationname like'%$search%' or applicationdescription '%$search%';"; $fullresult = mysqli_query($conn, $fullrecords); $foundnum = mysqli_num_rows($fullresult); if ($foundnum==0) echo "sorry, there no matching applications <b>$search</b>.</br></br>1. try more general words. example: if want search 'how write notes'then use general keywords 'notes' or 'write'.</br>2. try different words similar meaning.</br>3. please check spelling , 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 apps applicationname '%$search%' or applicationdescription '%$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 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; ($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>";
Comments
Post a Comment