Search three DB columns with one search field
-
Hi Mark, I’ve used CFDB and CFDB Editor together with Contact Form 7 to build a tool that helps me to rent out and track snorkeling equipment. The site runs on my LAN via a local wordpress install so unfortunately I can’t provide a link.
I’ve been able to use your examples to get everything working the way that I need it to, with the exception of one thing.
I use snorkeling bags that are numbered to allow quick identification of the gear when it gets returned. Each user can rent up to 3 bags which each have a unique ID number. These bag numbers get saved to three respective database columns namely: Bag-1, Bag-2, Bag-3.
Using [CFDB datatable] as you have instructed, I can search and output data for all the relevant columns however my search form uses three separate fields to search Bag-1, Bag-2, Bag-3 respectively. Is there any way to constrain this to just one search field within the same form?
This is the code for the Search Form
<form action="" method="POST"> <fieldset> <legend>Search by Name or Room Number</legend><label>First Name</label><input name="First-Name" type="text" id="search-first-name" /> <label>Last Name</label><input name="Last-Name" type="text" id="search-last-name" /><label>Room Number</label><input name="Room-Number" type="number" id="search-room-number" /></fieldset><fieldset><legend>Search by Bag Number</legend><label>Bag 1</label><input name="Bag-1" type="number" id="search-bag-1" /><label>Bag 2</label><input name="Bag-2" type="number" id="search-bag-2" /><label>Bag 3</label><input name="Bag-3" type="number" id="search-bag-3" /><label>Out</label><input class="radio-button" type="radio" name="Status" value="Out" checked="checked" /><label>In</label><input class="radio-button" type="radio" name="Status" value="In" /></fieldset><input name="x" value="1" type="hidden" /><input value="Search" type="submit" id="search-submit-button" /></form>
This is the code for the datatable:
[cfdb-datatable form="Equipment Rental" role="Editor" edit="cells" show="First-Name,Last-Name,Room-Number,Departure-Date,Full-Sets,Masks,Snorkels,Fins,Cameras,Optical-Masks,Bag-1,Bag-2,Bag-3,Status" filter="First-Name~~/.*$_POST(First-Name).*/i&&Last-Name~~/.*$_POST(Last-Name).*/i&&Room-Number~~/.*$_POST(Room-Number).*/i&&Bag-1~~/.*$_POST(Bag-1).*/i&&Bag-2~~/.*$_POST(Bag-2).*/i&&Bag-3~~/.*$_POST(Bag-3).*/i&&Status~~/.*$_POST(Status).*/i&&intval(1)=$_POST(x)"]
I have trawled through all CFDB support forums and I can’t find an answer to my question. Or at least not one that I clearly understand. Forgive me but my understanding of PHP and javascript is very limited. If you could assist me in getting this fixed, I would be very grateful.
CFDB and Editor are great plugins!
Best regards
Tomhttps://www.ads-software.com/plugins/contact-form-7-to-database-extension/
- The topic ‘Search three DB columns with one search field’ is closed to new replies.