我想在此搜索引擎中添加分頁。這是我曾嘗試:如何將分頁添加到搜索結果中?
//get date
$button = $_GET['submit'];
$search = $_GET['search'];
if (!$button)
echo "Please fill out the form";
else
{
if (strlen($search)<=2)
echo "The item you searched for was to small";
else
{
echo "You searched for <b>$search</b> <hr size='1'>";
//connect to database
mysql_connect('localhost','wnumber','passowrd');
mysql_select_db('wnumber');
//explode search term
$search_exploded = explode(" ",$search);
foreach($search_exploded as $search_each)
{
$str = mysql_real_escape_string(substr($search_each, 0, 4));
//construct query
$x++;
if ($x==1) $construct .= "keywords LIKE '$str%'";
else $construct .= " OR keywords LIKE '$str%'";
}
//echo out construct
$construct = "SELECT * FROM word WHERE $construct order by LENGTH(`keywords`)";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "No results found.";
else
{
echo "$foundnum results found.<p><hr size='1'>";
while ($runrows = mysql_fetch_assoc($run))
{
//get data
$meaning = $runrows['meaning'];
$keywords = $runrows['keywords'];
echo "<b>$keywords</b><br>
<b>$meaning</b><br>
}
}
}
}
在這個網站上有很多「如何添加分頁」問答。 –
例如這一個http://stackoverflow.com/questions/13807106/dynamic-pagination-depending-on-the-number-of-rows-in-mysql-database –