I have several drop lists where if no option is selected then the value is = ""...
I cant figure out how to build the query for mysql in PHP.
query = SELECT * FROM db
I have several drop lists where if no option is selected then the value is = ""...
I cant figure out how to build the query for mysql in PHP.
query = SELECT * FROM db
Too less information, but here's what I would do
$rows = $db->query(
'select *
from
table
where
checkbox_value = ?',
$_POST['checkbox']
);
In $rows
you will have all the data you need.
You can run a SELECT on a table not on a DB! A Database consists of many tables. See http://www.php.net/manual/en/function.mysql-select-db.php
Check out w3Schools sql tutorials.
Or more specifically the select tutorial
Also the PHP/mysql tutorial will give you all that you need for this stuff.
I assume you have a select like this:
<select name="data[]" multiple="multiple">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
Your php can be something like
<?php
$data = array();
$data = $_POST['data'];
$query = "select * from table";
if (count($data > 0)) {
for ($i = 0; $i < count($data); $i++) {
$data[$i] = "'{$data[$i]}'";
}
$query .= " where field in (".implode(",", $data).")";
}