tags:

views:

73

answers:

4

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

A: 

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.

michal kralik
I would do similar. However, you should consider what to do when the selected value is empty (like in the question).
Lukasz Lysik
A: 

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

powtac
A: 

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.

Derleek
+1  A: 

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).")";
}
Davide Gualano