I have a few days started studying php and i have the following code, which makes 3 checkboxes and 3 dropdown lists accordingly(could be more, thats not the issue). The idea is that a custom mysql query string will be created with more than one conditions.Dropdown lists will contain db fields. The user will decide how many custom conditions will add by clicking these checkboxes and setting a value in the dropdown list. After clicking the submit button for every checkbox that is checked and if a value from the according dropdown box is set, the value from the dropdown list will be read. The code works and returns the correct results (values from dropdown lists) only if ALL or only the FIRST checkbox are/is checked. For example if the second or third checkbox is check and a value for the dropdown list is set, the if statement ignores it. Obviously there is something wrong with the if statement (in specific && condition) inside the for loop but how can can fix it?. Additionally, if have only just one of the two conditions inside the if statement the results are correct, but i want both conditions to be true.
<?php
echo <<<_query
<form action="check_array.php" method="post">
query1<input type="checkbox" name="query[]" value="query0">
query2<input type="checkbox" name="query[]" value="query1">
query3<input type="checkbox" name="query[]" value="query2">
fields0
<select name="fields[]">
<option selected value="null">Select field</option>
<option value="author">author</option>
<option value="title">title</option>
<option value="category">category</option>
</select>
fields1
<select name="fields[]">
<option selected value="null">Select field</option>
<option value="author">author</option>
<option value="title">title</option>
<option value="category">category</option>
</select>
fields2
<select name="fields[]">
<option selected value="null">Select field</option>
<option value="author">author</option>
<option value="title">title</option>
<option value="category">category</option></form>
</select>
<input type="submit" name="submit" value="check"></form>
_query;
for ($i=0;$i<3;++$i){
if (isset($_POST["query"][$i]) && $_POST["fields"][$i] !="null"){
echo $_POST["query"][$i] ."<br>".$_POST["fields"][$i]."<br>";
}
}
?>
Aucun commentaire:
Enregistrer un commentaire