This is my very first PHP project, aside from tests I've executed in manuals. That being the case, I'm sure the solution will be apparent to experienced users, however it's not so apparent that I could find the solution with a thorough browsing of these forums and the internet at large.
The idea is to limit the TYPE of data that is ultimately presented in a list. My real problem is figuring out how to incorporate multiple search types in the MySQL SELECT string (see end of post), while taking the WHERE clauses from the checkboxes. As I understand it, I need a && between each result.
Anyway, here's the lovely form. There are three classes to each entry, and users can select whichever combination of the three they'd like. The fourth option in the form is to enable all the types.
<form action="test-j9c9e.php" method="get">
<ul>
<p><input type="checkbox" name="form_class" value="1"/>Strictly Legitimate kills, please.</p>
<p><input type="checkbox" name="form_class" value="2"/>Include Indeterminate kills.</p>
<p><input type="checkbox" name="form_class" value="3"/>Include Miscellanous kills.</p>
<p><input type="checkbox" name="form_class" value="4"/>Show me everything. </p>
</ul>
Once the values are passed to PHP, I've tried two functions to parse the data into its a usable format, neither of which I'm confident are 100% syntactically correct. I first tried a series of IF statements, but learned that they will simply bypass the remainder of the statements once they encounter a true statement. This does not work since I need users to be able to select MULTIPLE types.
if ($form_class = 1) {
$type = "'legitimate'";}
elseif ($form_class = 2) {
$type = "'indeterminate'";}
elseif ($form_class = 3) {
$type = "'miscellaneous'";}
elseif ($form_class = 4) {
$type = "'legitimate' && 'indeterminate' && 'miscellaneous'";}
elseif ($form_class = 1 && $form_class = 2) {
$type = "'legitimate' && 'indeterminate'";}
elseif ($form_class = 1 && $form_class = 3) {
$type = "'legitimate' && 'miscellaneous'";}
elseif ($form_class = 2 && $form_class = 3) {
$type = "'indeterminate' && 'miscellaneous'";}
elseif ($form_class = 1 && $form_class = 2 && $form_class = 3) {
$type = "'legitimate' && 'indeterminate' && 'miscellaneous'";}
And, a somewhat unwieldy switch(), which doesn't seem to work at all for the format...
switch($form_class)
{
case "1" : $type = 'legitimate';
case "2" : $type = 'indeterminate';
case "3" : $type = 'miscellaneous';
case "4" : $type = "'legitimate' && 'indeterminate' && 'miscellaneous'"; break;
}
And here we run into the brick wall. The syntax from the results of the IF/Switch statements don't compute with the MySQL query as is...:
$query="SELECT * FROM roster WHERE classs = $type";
Thanks in advance!
PS: And yes, I'm aware 'classs' is not supposed to have 3 s's. However, I couldn't get it to work as 'class' The data is reads from the MySQL database also reads as 'classs' so, it's merely superficial.