Jump to content

Pagination + Search problem


blink359

Recommended Posts

Hi there

Im trying to add a search feature to my pagination but with some googling and searching have had no luck and have also had no luck trying myself this is what i have so far

Form

<form action="publist.php" method="post">
Search: <input type="text" name="search"> By: 
<select name="by">
<option value="name" selected="selected">Name</option>
<option value="town">Town</option>
<option value="county" >County</option> 
</select> Results Per Page: <select name="perpage">
<option value="10" selected="selected">10</option>
<option value="25">25</option>
<option value="50" >50</option> 
</select>
<input type="hidden" name="hidden">
<input type="submit" value="Search">
</form>

Related code:

if(isset($_POST['hidden'])){
$by = $_POST['by'];
$search = $_POST['search'];
$sql = "SELECT * FROM table WHERE approved = 'Yes' AND '. $by .' = '. $search .' LIMIT $offset, $rowsperpage";
}else{
$sql = "SELECT * FROM table WHERE approved = 'Yes' LIMIT $offset, $rowsperpage";
}
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);


while ($list = mysql_fetch_assoc($result)) {

echo'
<table width="700" border="1">
  <tr>
    <td colspan="3">'. $list['name'] .'</td>
  </tr>
  <tr>
    <td height="24">Town: '. $list['town'] .'</td>
    <td>County: '. $list['county'] .'</td>
    <td>Postcode: '. $list['postcode'] .'</td>
  </tr>
  <tr>
    <td>Contact Number: '. $list['phone'] .'</td>
    <td>Email: '. $list['pubemail'] .'</td>
    <td><a href="info.php?id='. $list['ID'] .'">More Information</a></td>
  </tr>
</table><br>';


}

But when i try the search it comes out blank,

 

Any help would be great

 

 

Thanks,

 

Blink359

Link to comment
https://forums.phpfreaks.com/topic/222495-pagination-search-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.