I have this combo box, to select a day a given flight in this case operates on.
<select style="border:1px solid #DCDCDC; color:#003663; font-size:11px;" class="search" name="day" id="day">
<option value="0">Sunday</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
<option value="6">Saturday</option>
</select>
The table we’ll be looking for information is called db_schedules. The table structure contains a column called daysofweek. 0123456 specify days, 0 being a Sunday, 1-6 Monday-Saturday. Each record has a specified daysofweek value i.e schedule 3 is enabled in searches on days 346.
Based on the above, how do I query the database for a search based upon the selected option from the combo box?
It’s not clear, from the question, the datatype of column
daysofweek, whether that’s a varchar and you’re storing a string that indicates a set of days, (e.g a value of ‘1235’ representings Mon, Tue, Wed and Fri), or whether that’s an integer column, and you have multiple rows, one for each day.If it’s a VARCHAR column, to search for days 3, 4 and 6, if you want any db_schedule row that matches any of those days:
To get a match on all the days, the
ANDthose predicates rather thanORthemA
REGEXPcould be used in place of theLIKE. In the case of an “OR” conditions, e.g. to find matches on ‘3’,’4′ or ‘6’:An
INSTRfunction would also work:Without more detailed information about the exact problem you are facing, it’s really not productive to suggest other solutions.
But we might point out that there might be more appropriate datatypes for storing
daysofweek, the MySQLSETdatatype would seem to fit the bill.Followup:
If days of week is stored as a VARCHAR(7), and you want to pass in arguments of ‘Tuesday’, ‘Wednesday’ and ‘Friday’ into a SQL query to perform the search…
I just don’t understand why you would go to the bother of translating the value(s) returned from the select dropdown box into a character strings like ‘Sunday’, ‘Monday’, etc.
The values being returned (according to your HTML code, they would be “0” thru “7”), and those already “match” the values stored in the database.