Hi,
Basically I want to execute a dynamically created SQL statement based on user input.
Here is my thought.
Two select boxes one called 'Product' the other called 'Category'.
Now initially when the page first loads it will show all technical articles, and then if the user wishes they can filter the list using the boxes available. i.e. Product AND Category, just Product, just Category.
The problem I have here I have no idea how to create an SQL select based on user input that is posted to the same php page.
Any indicators as to where I can info on doing this will be greatly appreciated.
SQL statements created 'on the fly' with PHP.
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Use something like....
Hope this helps
Code: Select all
// POTENTIAL SECURITY NOTICE : need to check here for validity
$variable1=floor($_POST['cat']);
// Calculate filter
if ($variable1) {
$sql_add=" AND columnx=$variable1";
} else {
$sql_add="";
}
$query=" SELECT * from table1 WHERE test='i dont know".$sql_add;
// Perform the query