textbox disappears in paging - php
- by fusion
i'm calling the search.php page via ajax to search.html. the problem is, since i've implemented paging, the textbox with the search keyword from search.html 'disappears' when the user clicks the 'Next' button [because the page goes to search.php which has no textbox element]
i'd like the textbox with the search keyword to be there, when the user goes through the records via paging. how'd i achieve this?
search.html:
<body>
<form name="myform" class="wrapper">
<input type="text" name="q" onkeyup="showPage();" class="txt_search"/>
<input type="button" name="button" onclick="showPage();" class="button"/>
<p>
<div id="txtHint"></div>
<div id="page"></div>
</form>
</body>
search.php [the relevant part]:
$self = $_SERVER['PHP_SELF'];
$limit = 5; //Number of results per page
$numpages=ceil($totalrows/$limit);
$query = $query." ORDER BY idQuotes LIMIT " . ($page-1)*$limit . ",$limit";
$result = mysql_query($query, $conn)
or die('Error:' .mysql_error());
?>
<div class="caption">Search Results</div>
<div class="center_div">
<table>
<?php while ($row= mysql_fetch_array($result, MYSQL_ASSOC)) {
$cQuote = highlightWords(htmlspecialchars($row['cQuotes']), $search_result);
?>
<tr>
<td style="text-align:right; font-size:15px;"><?php h($row['cArabic']); ?></td>
<td style="font-size:16px;"><?php echo $cQuote; ?></td>
<td style="font-size:12px;"><?php h($row['vAuthor']); ?></td>
<td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']); ?></td>
</tr>
<?php } ?>
</table>
</div>
<?php
//Create and print the Navigation bar
$nav="";
if($page > 1) {
$nav .= "<a href=\"$self?page=" . ($page-1) . "&q=" .urlencode($search_result) . "\">< Prev</a>";
$first = "<a href=\"$self?page=1&q=" .urlencode($search_result) . "\"><< First</a>" ;
}
else {
$nav .= " ";
$first = " ";
}
for($i = 1 ; $i <= $numpages ; $i++) {
if($i == $page) {
$nav .= "<B>$i</B>";
}else{
$nav .= "<a href=\"$self?page=" . $i . "&q=" .urlencode($search_result) . "\">$i</a>";
}
}
if($page < $numpages) {
$nav .= "<a href=\"$self?page=" . ($page+1) . "&q=" .urlencode($search_result) . "\">Next ></a>";
$last = "<a href=\"$self?page=$numpages&q=" .urlencode($search_result) . "\">Last >></a> ";
}
else {
$nav .= " ";
$last = " ";
}
echo "<br /><br />" . $first . $nav . $last;
}