Man or Animal
05-14-2006, 08:48 PM
Hi, I'm currently trying to build an "advanced" search form for searching my database. On the form, there are a couple of field that if left blank, I'd like it to search ALL records from that specific field. For example, the input field on the search form is a simple "yes/no" option that isn't filled in by default. The database field for it will always be either yes or no, and if the user doesn't select an option, I'd like it to display the records regardless of the database field being "yes" or "no" (plus it has to meet the other criteria). I have everything else working... I just can't seem to get this particular feature working correctly.
Thanks for any help!
Man or Animal
05-14-2006, 09:21 PM
Sure. The PHP source is really long so here's the relevant part:
if (isset($_GET['memb_st'])) {
$memb_st = clean($_GET['memb_st']);
}
else{
$memb_st = 'ALL';
}
if (isset($_GET['quest_st'])) {
$quest_st = clean($_GET['quest_st']);
}
else{
$quest_st = 'ALL';
}
if (isset($_GET['sort_by'])) {
$sort_by = clean($_GET['sort_by']);
}
else{
$sort_by = 'desc';
}
if (isset($_GET['item_ty'])) {
$item_ty = clean($_GET['item_ty']);
if($item_ty == 'yes'){
@$item_inc = clean($_GET['item_inc']);
}
}
if (isset($_GET['pageno'])) {
$pageno = clean($_GET['pageno']);
}
else{
$pageno = 1;
}
if (isset($_GET['category'])) {
$cat = clean($_GET['category']);
}
else{
$cat = 'Name';
}
if (isset($_GET['order'])) {
$order = clean($_GET['order']);
}
else{
$order = 'Name';
}
if ($search == ""){
echo "<p class='regs'>You didn't enter anything to search for, please search again.</p>";
show_form();
}
else if (strlen($search) <= 1){
echo "<p class='regs'>Please enter at least 2 characters to search for.</p>";
show_form();
}
else if ($cat == ""){
echo "<p class='regs'>You didn't enter a category to search by!</p>";
}
else{
$query = "SELECT count(*) FROM items WHERE $cat LIKE '%$search%' AND Member = '$memb_st' AND QuestItem = '$quest_st' AND Type = '$item_inc' ORDER by '$order' $sort_by";
Near the top of that code are the 2 variables that I'm trying to get search both yes and no in the specific field (the ones with "ALL" as the value).
Man or Animal
05-14-2006, 10:42 PM
Sorry for the double post, but I can't edit my last post... I managed to get it working by putting those two queries into variables, then just using the variables in the main query. I guess that works. :P
Now I'm having trouble with checkboxes... I want the user to be able to check as many boxes as they want out of a list of say, 10, and it searches another field for anything that matches the values of the checkboxes. I have the checkboxes set up as arrays but when I look at the query it shows that it's blank... Can anyone help with that? :)
tmark938
05-16-2006, 10:48 AM
Are there any MySql experts out there who would listen to a possible Joint Venture?