Hello Friends,

I am having trouble figuring out how to get me Radio Buttons to search my database. Everything is up on the page and when I select enter it just shows all the items as if nothing was entered. There was already a set search button in the script that let's you type keywords typed in, I am trying to get the grid of radio buttons to do the same thing with the appointed name for the button to be search for. Can Someone Help Please?

This is the code for the search with the keyword typed:

<form name="frmsearch" id="frmsearch" method="get" action="search.php">
<div align="right">
<input name="q" type="text" class="date" id="q" value="[|keyword|]" size="25" maxlength="50" />
<input name="Search" type="submit" class="date" id="Search" value="Search" />
</div>
</form>

And this is the code I have for the Search Grid tables:

<div id="searchAmenFirst">
<div id="blueHeadMd">
<div id="blueHeadLeft">
<p><strong>Beds/Baths:</strong>
<label class="searchLabelSm" for="beds">Beds</label>
<select id="beds" class="searchDropSm" name="beds" ="beds" onchange="javascript:get_Area_Count()">
<option value="-200" selected="selected">Any </option>
<option value="Studio">Studio </option>
<option value="1Bedroom">1Bedroom</option>
<option value="2Bedrooms">2Bedrooms</option>
<option value="3Bedrooms">3Bedrooms</option>
<option value="4Bedrooms">4Bedrooms</option>
<option value="5+Bedrooms">5+Bedrooms</option>
</select>
<label class="searchLabelSm" for="baths">Baths</label>
<select id="beds" class="searchDropSm" name="baths" ="baths" onchange="javascript:get_Area_Count()">
<option value="Bath" selected="selected">Any </option>
<option value="1Bath">1Bath</option>
<option value="1.5Bath">1.5Bath </option>
<option value="2Bath">2Bath </option>
<option value="2.5Bath">2.5Bath </option>
<option value="3Bath">3Bath </option>
<option value="3.5Bath">3.5Bath </option>
<option value="4+Bath">4+Bath </option>
</select>
</p>
<p>&nbsp;</p>
</div>
<h4 class="boxHead" id="Apartment Features">Apartment Features<font color="#FFFFFF"> -----------</font>Community Features<font color="#FFFFFF">------</font>Pets</h4>
</div>
<div id="searchAmenCont">
<input class="frmsearch" type="checkbox" id="Air Conditioning" name="Air Conditioning" value="Air_Conditioning" />
<label class="searchChLabel" for="Air_Conditioning">Air Conditioning</label>
<font color="#FFFFFF">--
------
-</font>
<input class="searchCheck" type="checkbox" id="amenity[]2" name="amenity[]2" value="Controlled_Access" />
<label class="searchChLabel" for="Controlled_Access">Controlled Access</label>
<font color="#FFFFFF">-----</font>
<input class="searchCheck" type="checkbox" id="amenity[]11" name="amenity[]11" value="All_Dogs_Allowed" />
<label class="searchChLabel" for="All_Dogs_Allowed">All Dogs Allowed</label>
<br class="clear" />
<input class="searchCheck" type="checkbox" id="amenity[]" name="amenity[]" value="Alarm_System" />
<label class="searchChLabel" for="Alarm_System">Alarm System</label>
<font color="#FFFFFF">----
------
-</font>
<input class="searchCheck" type="checkbox" id="amenity[]3" name="amenity[]3" value="Disability_Access" />
<label class="searchChLabel" for="Disability_Access">Disability Access</label>
<font color="#FFFFFF">-------</font>
<input class="searchCheck" type="checkbox" id="amenity[]12" name="amenity[]12" value="Cats_Allowed" />
<label class="searchChLabel" for="Cats_Allowed">Cats Allowed</label>
<br class="clear" />
<input class="searchCheck" type="checkbox" id="amenity[]" name="amenity[]" value="Cable_or_Satellite" />
<label class="searchChLabel" for="Cable_or_Satellite">Cable or Satellite</label>
<font color="#FFFFFF">---------</font>
<input class="searchCheck" type="checkbox" id="amenity[]4" name="amenity[]4" value="Fitness_Center" />
<label class="searchChLabel" for="Fitness_Center">Fitness Center</label>
<font color="#FFFFFF">------- --</font>
<input class="searchCheck" type="checkbox" id="amenity[]13" name="amenity[]13" value="Pets_Allowed" />
<label class="searchChLabel" for="Pets_Allowed">Pets Allowed</label>
<br class="clear" />
<input class="searchCheck" type="checkbox" id="amenity[]" name="amenity[]" value="Dishwasher" />
<label class="searchChLabel" for="Dishwasher">Dishwasher</label>
<font color="#FFFFFF">------------- -</font>
<input class="searchCheck" type="checkbox" id="amenity[]5" name="amenity[]5" value="Garages" />
<label class="searchChLabel" for="Garages">Garages</label>
<font color="#FFFFFF">----------------</font>
<input class="searchCheck" type="checkbox" id="amenity[]14" name="amenity[]14" value="Small_Dogs_Allowed" />
<label class="searchChLabel" for="Small_Dogs_Allowed">Small Dogs Allowed</label>
<br class="clear" />
<input class="searchCheck" type="checkbox" id="amenity[]" name="amenity[]" value="Fireplace" />
<label class="searchChLabel" for="Fireplace">Fireplace</label>
<font color="#FFFFFF">-----------------</font>
<input class="searchCheck" type="checkbox" id="amenity[]6" name="amenity[]6" value="Golf Course" />
<label class="searchChLabel" for="Golf Course">Golf Course</label>
<font color="#FFFFFF">------------</font>
<input class="searchCheck" type="checkbox" id="amenity[]15" name="amenity[]15" value="No_Pets" />
<label class="searchChLabel" for="Small_Dogs_Allowed">No Pets</label>
<br class="clear" />
<input class="searchCheck" type="checkbox" id="amenity[]" name="amenity[]" value="Furnished_Available" />
<label class="searchChLabel" for="Furnished_Available">Furnished Available</label>
<font color="#FFFFFF">------</font>
<input class="searchCheck" type="checkbox" id="amenity[]7" name="amenity[]7" value="Laundry_Facility" />
<label class="searchChLabel" for="Laundry_Facility">Laundry Facility</label>
<br class="clear" />
<input class="searchCheck" type="checkbox" id="amenity[]" name="amenity[]" value="Patio_or_Balcony" />
<label class="searchChLabel" for="Patio_or_Balcony">Patio or Balcony</label>
<font color="#FFFFFF">---------</font>
<input class="searchCheck" type="checkbox" id="amenity[]8" name="amenity[]8" value="Playground" />
<label class="searchChLabel" for="Playground">Playground</label>
<br class="clear" />
<input class="searchCheck" type="checkbox" id="amenity[]" name="amenity[]" value="Washer_Dryer_Hookup" />
<label class="searchChLabel" for="Washer_Dryer_Hookup">Washer Dryer Hookup</label>
<font color="#FFFFFF">- -</font>
<input class="searchCheck" type="checkbox" id="amenity[]9" name="amenity[]9" value="Pool" />
<label class="searchChLabel" for="Pool">Pool</label>
<br class="clear" />
<input class="searchCheck" type="checkbox" id="amenity[]" name="amenity[]" value="Washer_Dryer_In_Unit" />
<label class="searchChLabel" for="Washer_Dryer_In_Unit">Washer Dryer In Unit</label>
<font color="#FFFFFF">---- </font>
<input class="searchCheck" type="checkbox" id="amenity[]10" name="amenity[]10" value="Short_Term_Lease" />
<label class="searchChLabel" for="Short_Term_Lease">Short Term Lease</label>
<div align="center" id="searchSubmitMain">
<form name="frmsearch" id="frmsearch" method="get" action="search.php"><input name="submit" type="image" onclick="return validate_areasearch();" src="../btn_searchrentals.png" alt="Search Apartments" width="158" height="32" border="0" />
</form></div>
<br class="clear" />
</div>
</div>

Okay,
I figured out what I was doing to get the search to recognize the Check Box.
But I have no clue on how to have the search recognize multiple check boxes at the same time.
Can anyone figure this one out? The code I am using is below. Also if you know how to make a Drop box access a search too all at the same time.

Thanks People!

<form name="frmsearch" id="frmsearch" method="get" action="search.php">
                  <p>Search: 
                    <input name="q" type="text","checkbox","searchDropSm", "radio" class="date" id="q" value="[|keyword|]" size="25" maxlength="50" />
<br>
Search Just:
No Pets
<input type="checkbox" name="q" value="No Pets">
Laundry Facility
<input type="checkbox" name="q" value="Laundry Facility">
Field 3
<input type="checkbox" name="q" value="field3">
Field 4
<input type="checkbox" name="q" value="field4">
                  </p>
                  <p>
                    <input name="Search" type="submit" class="date" id="Search" value="Search" />
                                    </p>
                </form><br class="clear" />

you have given your checkboxes a name, and a value... Each check box needs to be referenced on your search.php page....

$amenity9 = $_GET['amenity9'];
$amenity10 = $_GET['amenity10'];

Here $amenity9 should give you the value that is passed, if it is checked, it will pass the value itself... if it is not checked NO VALUE IS PASSED.

actually, something is passed, it should be an empty string if memory serves me right.

You shouldn't have [] in the name of your checkbox.... it should just be a string with no characters... this might be throwing things off... If you want to make sure that you know it's a checkbox when you are looking at it... call it something like
chkbxAmenity1

Now, you have to deal with the information in your search.php page, both within php and then again in the sql statement that you create.

If you are searching in the same field (column in your database), it's a bit easier but you will still be dealing with a lot of of "if statements".

Don't even worry about using the above code I wrote if you choose this rout.

if ($_GET['amenity9'] != ""){
$condition = .$condition. .$_GET['amenity9']. ",";
}

if ($_GET['amenity10'] != ""){
$condition = $condition. .$_GET['amenity9']. ",";
}

What you are doing here is saying "if the value of amenity10 is not empty, concatinate this value with condition". You do not need an "else" statement, because you don't really care about what happens if it is actually an empty string.

You may need to check my concatination systax a little bit, since it's been a while since I've done this in PHP and I am pulling this straight from memory, but, this should put you on the right track.

Now, for the last issue.
At the end of it all, you will probably have an extra comma. So, we need to get rid of it.

$condition = $condition{strlen($condition)-1};

Now, your sql statement itself would be

SELECT * FROM table WHERE  field IN ($condition);

You are building a sql statement that actually looks like

SELECT * FROM table WHERE  field IN (amenity1, amenity2, amenity3, amenity4);

But, all the stuff between ( and ) is held by the variable $condition


which should search the column named field for each of those values and return any record which has one or more of those values in it.

NOTE: I have made some changes to the code, so, if you read it before, you may need to read it again. I'm still not 100 percent sure if the concatination itself is correct, but, just know that you need to make the value of $_GET have a comma right after it, and concatinate that all to the end of $condition.

Hope this helps
Sage

Thanks Sage!

What I am actually doing, is working on a scripting program that I purchased.
And The .html templates are editable which I did through Dreamweaver.
So the thing that I am doing and seems to wirk, is that when I use this other code other than the original that I posted, I can make a single checkbox enter the information in the search.
The thing I would like to do, is click multiple check boxes that add to the search as separate words that enter, if that makes any sense. So in a sense, if I made two boxes, that search for two different words. One says "No Pets" - And the other says "Laundry Facility" and when I click the search button, it searches all the words in each product of the database. Which I have working now. But the problem I have it that which ever one I click first is the only one that is searched for. Do you know how to make this code I am attaching, search for Each word as if they are seperated by a comma if multiple ones are clicked?

I truly appreciate all the for mentioned information earlier.
Thank you. CopperK AkA -JoE
Code Below.

<form name="frmsearch" id="frmsearch" method="get" action="search.php">
                  <p>Search: 
                    <input name="q" type="text","checkbox","searchDropSm", "radio" class="date" id="q" value="[|keyword|]" size="25" maxlength="50" />
<br>
Search Just:
No Pets
<input type="checkbox" name="q" value="No Pets">
Laundry Facility
<input type="checkbox" name="q" value="Laundry Facility">
Field 3
<input type="checkbox" name="q" value="field3">
Field 4
<input type="checkbox" name="q" value="field4">
                  </p>
                  <p>
                    <input name="Search" type="submit" class="date" id="Search" value="Search" />
                                    </p>
                </form><br class="clear" />

Well, it's not really going to work by doing it this way, or at least, no way that I can think of.
See, you've made it pass all kinds of information to through the url.

http://www.domain.com/form/search.php?q=%5B%7Ckeyword%7C%5D&q=No+Pets&q=Laundry+Facility&q=field3&Search=Search

you've made q be one thing, than another, than another.
This isn't even an array, it takes the last q definition that you have given.

The best way to handle this really would be to give each a name as I described above.

Someone else might have a solution to how you are doing it now, but I am not sure about that even.

If this was being passed as an array I would certainly know how to handle that, as it is, you've got values canceling eachother out.
Sage

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.