notsoevilgenius
MIS
Can anyone help me add a search box into my code where the user can filter the database better? A have page that list people from a donors table. By default when the page opens it returns everyone in alphabetical order by last name then first name. Above the table on the page are alphabet buttons to filter the list. I'd like to put the search either before the A, after the Z or under the alphabet buttons entirely.
Button Code
php and mysql code
Thank you!
Button Code
Code:
<script>
var btns = "";
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var letterArray = letters.split("");
for(var i = 0; i < 26; i++){
var letter = letterArray.shift();
btns += '<button class="mybtns" onclick="alphabetSearch(\''+letter+'\');">'+letter+'</button>';
}
function alphabetSearch(let){
window.location = "donorList.php?letter="+let;
}
</script>
php and mysql code
Code:
<?php
$letter = "";
if(isset($_GET['letter']) && strlen($_GET['letter']) == 1){
$letter = preg_replace('#[^a-z]#i', '', $_GET['letter']);
}
$sql = "SELECT * FROM donors WHERE lastname LIKE '$letter%' ORDER BY lastname, firstname";
$result = mysql_query($sql) or die(mysql_error());
?>
<h4>Donor List</h4>
<p style="margin-left:25px;"> Clicking on an A thru Z button will return names that start with that letter.</p>
<p style="margin-left:25px;"> Clicking on a table column header will sort the entire list by that heading.</p>
<p style="margin-left:25px;"><script> document.write(btns);</script>
<table...
Thank you!