从Javascript选择中选择SQL查询

https://docs.google.com/file/d/0B9urXGIYtvx-YzdYNlllbUxFeHM/edit?usp=drive_web

Attached is a picture of what I have done so far. This is just the front end and I need help with the backend.

I have a question about using SQL to bring up a table based on these selections. I created these dropdowns and selections using javascript but I want to be able to pass them on to a sql to search the database based on selections and return anything that fits the criteria.

To explain everything:

I want to lists at the bottom to be apart of the Select (ex. Select OrganizationID, OrganizationName, OrganizationType, EventID, EventName)

Then I would like the two selections at the top to be the FROM (ex. FROM Events, Organization) and then of course join these with a WHERE.

Then I would like the include or exclude to be apart of the WHERE (ex. WHERE EventID=32211)

I know that I will have to use PHP for this as well and that's perfectly fine I just need help starting it to find out how to pass these selections.

the easiest way is to wrap everything in a FORM tag with an action property. The action property will specify the page you'll be sending the data to (via an http post by default).

so you could put action="searchresults.php", for example.

Your server will receive the values from all of the inputs on your page inside of the $_POST variable. The $_POST variable is an associative array where the key is the name attribute of the input elements.

so to get the values the people entered you'd do something like this:

if (isset($_POST)){
    $table=$_POST["Table"]; //where Table is the name of your first option box, it should get the value assigned to the option element.
}

After you get the values, you need to build out your query. The ONLY ways you should EVER consider doing this is through either a prepared statement or a stored procedure.

here's the php documentation on MSSQL prepared statements: http://us2.php.net/sqlsrv_prepare

the long and the short of it:

//$conn is the database connection, $params is an array of the parameters to fill in the ?.
$sql = "SELECT FROM table WHERE id=?";
$stmt=sqlsrv_prepare ($conn, $sql , $params);

NEVER build a query by concatenating user inputs, this leaves you open to SQL injection attacks.

If you'd like some more specifics, you're going to have to provide more information, a database schema, the HTML on your form, some expected results.