notsoevilgenius
MIS
Hello! Can anyone help me add a user input to filter mysql database return. Right now I'm using alphabet buttons to filter the table return of a list of names from a donor table. They work great and I'd like to keep them.
The user would like an either AND process where in addition to being able to click a button like say J and return Jackson, Jason, Jenson and Johnson, but to also be able to enter in ja and return Jackson and Jason or type in jac and return Jackson.
The php/mysql code (I don't think this needs to change)
Thanks!
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>
The user would like an either AND process where in addition to being able to click a button like say J and return Jackson, Jason, Jenson and Johnson, but to also be able to enter in ja and return Jackson and Jason or type in jac and return Jackson.
The php/mysql code (I don't think this needs to change)
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 [b]'$letter%'[/b] 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;">[b]<script> document.write(btns);</script>[/b]
<table...
Thanks!