How can I add a filter option to be displayed only when the table displays more than 25 results. So when the table displays less than 25 results, the filter option will also no longer be displayed.

<div class="container">

    <div class="row">
        <div class="col-md-6">
            <h2> Dicey Dining Results</h2>
        </div>
    </div>

<?php

$button = $_GET ['submit'];
$search = $_GET ['search']; 

if(strlen($search)<=1)
echo "Search term too short";
else{
mysql_connect("saintbernard.lininteractive.com","admin_dicey","hfRd84^6");
mysql_select_db("admin_diceydining");

$search_exploded = explode (" ", $search);

$x = "";
$construct = "";  

foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="Name LIKE '%$search_each%'";
else
$construct .="AND PCITY LIKE '%$search_each%'";

}

$constructs ="SELECT * FROM broadway WHERE $construct";
$run = mysql_query($constructs);

$foundnum = mysql_num_rows($run);

if ($foundnum==0)
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1. 
Try more general words. for example: If you want to search 'how to create a website'
then use general keyword like 'create' 'website'</br>2. Try different words with similar
 meaning</br>3. Please check your spelling";
else
{ 


$per_page = 25;
$start = isset($_GET['start']) ? $_GET['start']: '';
$max_pages = ceil($foundnum / $per_page);
if(!$start)
$start=0; 
$getquery = mysql_query("SELECT * FROM broadway WHERE $construct LIMIT $start, $per_page");

    echo "<table data-toggle='table' data-sort-name='name' data-sort-order='desc'>";
    echo "<thead>";
    echo "<tr>";
    echo "<th data-sortable='true'>Date</th><th data-field='Name' data-align='left' data-sortable='true'>Name</th><th>City</th><th>Description</th>";
    echo "</tr>";
    echo "</thead>";

    while($runrows = mysql_fetch_assoc($getquery)) {
    // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
    echo "<tr>";
    echo "<td>{$runrows['Name']}</td>";
    echo "<td>{$runrows['PCITY']}</td>";
    echo "<td>{$runrows['TYPE']}</td>";
    echo '<td><a href="results2.php?nameID=' .$runrows['ID'].'">' .substr($runrows['DESCR'], 0, 35) .'</a></td>';
    echo "</tr>";
    // posts results gotten from database(title and text) you can also show id ($results['id'])

    }

    echo "</table>";

//Pagination Starts
echo "<center>";

$prev = $start - $per_page;
$next = $start + $per_page;

$adjacents = 3;
$last = $max_pages - 1;

if($max_pages > 1)
{   
//previous button
if (!($start<=0)) 
echo " <a class='pagination' href='dicey_search.php?search=$search&submit=Search+source+code&start=$prev'>Prev</a> ";    

//pages 
if ($max_pages < 7 + ($adjacents * 2))   //not enough pages to bother breaking it up
{
$i = 0;   
for ($counter = 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a class='pagination' href='dicey_search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a class='pagination' href='dicey_search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}  
$i = $i + $per_page;                 
}
}
elseif($max_pages > 5 + ($adjacents * 2))    //enough pages to hide some
{
//close to beginning; only hide later pages
if(($start/$per_page) < 1 + ($adjacents * 2))        
{
$i = 0;
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($i == $start){
echo " <a class='pagination' href='dicey_search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a class='pagination' href='dicey_search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
} 
$i = $i + $per_page;                                       
}

}
//in middle; hide some front and some back
elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2))
{
echo " <a class='pagination' href='dicey_search.php?search=$search&submit=Search+source+code&start=0'>1</a> ";
echo " <a class='pagination' href='dicey_search.php?search=$search&submit=Search+source+code&start=$per_page'>2</a> .... ";

$i = $start;                 
for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++)
{
if ($i == $start){
echo " <a class='pagination' href='dicey_search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a class='pagination' href='dicey_search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}   
$i = $i + $per_page;                
}

}
//close to end; only hide early pages
else
{
echo " <a class='pagination' href='search.php?search=$search&submit=Search+source+code&start=0'>1</a> ";
echo " <a class='pagination' href='search.php?search=$search&submit=Search+source+code&start=$per_page'>2</a> .... ";

$i = $start;                
for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a class='pagination' href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a class='pagination' 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 class='pagination' href='search.php?search=$search&submit=Search+source+code&start=$next'>Next</a> ";    
}  


echo "</center>";
} 
} 
?>
</div>

thank you for any assistance that can be given

Member Avatar for diafol

THe whole "echo" stuff is very hard to maintain. Try to avoid using deprecated tags like <center> and php functions like mysql_*. In addition it looks very convoluted. I'll have a shot at looking at it in a little while...

i really appreciate it! thank you!

THe whole "echo" stuff is very hard to maintain.

PHP is not my thing, but I always wondered why plain HTML is being echo'd in PHP. I mean i could see the point if you were building a table or a list from a data source, but for "non-dynamic" data..??.. Why not just include the HTML without the echo. I dont get it.

Member Avatar for diafol

i really appreciate it! thank you!

I'm sorry, been busy - will take longer than I thought. Maybe tomorrow. ANybody else in the meantime?

if its something that can't be done, please don't stress yourself over it. thanks

if ($foundnum > 25)
{
    // output the filter option here
}

Although I'm not clear on what you want to put in it (yet).

I'm looking to implement a search and filter upon a field. So that will be displayed depending on number of results shown

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.