2013-08-31 18 views
0

我有一個搜索欄,返回值,我想分頁結果,但是,我的網址已經search.php?result=whateverresultis,我試圖簡單地把?page=whatever後,它的所有結果都消失了。這是我的代碼目前:如何與已修改的網址分頁?

<?php 
include("config.php"); 
$search = mysql_real_escape_string($_GET['result']); 
?> 
<HTML> 
<HEAD> 
<title>Envy Dayz | <?php echo $search; ?></title> 
</HEAD> 
<BODY> 
<div id="wrapper"> 
<div class="searchleft"> 
</div> 
<div class="search"> 
<center> 
<form method="get" action="search.php"> 
<input type="text" name="result" value="<?php echo $search; ?>" /> 
<input type="submit" /> 
</form> 
<?php  
$data = mysql_query("SELECT * FROM shop 
    WHERE MATCH (name,description,keywords) AGAINST ('$search' IN BOOLEAN MODE)") or die(mysql_error()); 

$num_rows = mysql_num_rows($data); 

if ($num_rows == "1") { 
    echo "Returned 1 result."; 
} else { echo "Returned ".$num_rows." results."; } 

while ($info = mysql_fetch_assoc($data)) { 
    $name = stripslashes($info['name']); 
    $desc = stripslashes($info['description']); 
    $desc = substr($desc, 0, 150); 
    $price = stripslashes($info['price']); 
    Print "<div style=\"width:600px; height:150px; border:1px solid black; overflow:hidden\"><div style=\"height:148px; width:25%; border:1px solid red; float:left\"><center><img src=\"".$picture."\" height=\"120\" width=\"120\" style=\"margin-top:15px\" /></center></div><div style=\"height:150px; width:50%; border:1px solid blue; float:left; text-overflow: ellipsis; padding-top:5px\"><center><font size=\"+1\"><b><a href=\"result.php?product=".urlencode($name)."\">".$name."</b></a></font><br><br>".$desc."...</center></div><div style=\"height:150px; width:24%; border:1px solid green; float:left\"><center><h1>$".$price."</h1><button>Add to Cart</button></center></div></div>"; 
} 
?> 

我該如何去分頁與每頁10個結果?

+0

你應該使用'&頁= whatever'不'?' – bansi

+0

追加更多的變量來查詢字符串'&'。 '?'只能用於標記查詢字符串的開頭。 –

回答

0

試試這個

的search.php?結果= whateverresultis &頁=無論