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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.