目前,我有一个带有相应搜索结果的渲染表。我的问题,我如何添加一个过滤器选项,它将过滤特定字段,但仅当表格呈现超过25个结果时?
<?php
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(strlen($search)<=1)
echo "Search term too short";
else{
mysql_connect("*******.lininteractive.com","**********","********");
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>";
答案 0 :(得分:0)
您可以执行查询计算结果,如
SELECT COUNT(*)FROM broadway WHERE $ construct;
在您知道结果的行号后,您可以选择要执行的操作。