Jump to content

search mysql with checkbox array


dschuett

Recommended Posts

Ok I am very new to the php mysql world so please bare with me.

 

I have set up a database for an apartment complex with a table containing the following:

 

create table apartments (apt_num int not null, available varchar(5) not null, beds int not null, baths int not null, pets varchar(5) not null, lease_start varchar(25), lease_end VARCHAR(25), descr varchar(25) not null, primary key (apt_num));

 

I am now creating a form that contains check boxes for users to select what they want to search for, and return the correct results... for example:

 

<input type=”checkbox” checked="checked" name=”bdrm[]” value=”Any″>

<input type=”checkbox” name=”bdrm[]” value=”1″>

<input type=”checkbox” name=”bdrm[]” value=”2″>

<input type=”checkbox” name=”bdrm[]” value=”3″>

 

<input type=”checkbox” checked="checked" name=”btrm[]” value=”Any″>

<input type=”checkbox” name=”btrm[]” value=”1″>

<input type=”checkbox” name=”btrm[]” value=”2″>

 

<input type=”checkbox” checked="checked" name=”pets[]” value=”Any″>

<input type=”checkbox” name=”pets[]” value=”Yes″>

<input type=”checkbox” name=”pets[]” value=”No″>

 

my question is: how would i use php to insert it into a query such as this:

 

SELECT * FROM apartments WHERE beds='bdrmChecked' AND baths='btrmChecked' AND pets='petsChecked';

 

Another problem is that if a user checked "Any" it wouldn't return any results because the value "Any" wouldn't exist in the table...

 

Any help is appreciated!

Link to comment
https://forums.phpfreaks.com/topic/211343-search-mysql-with-checkbox-array/
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.