Dynamically generating sql statements is quite simple.
The database functions in PH work with strings, so the sql statement can be a string stored in a variable....
in pseudo code:
$my_sql_statement = "select ";
if ($looking_for_column_a)
{
$my_sql_statement .=" column_a ";
}
else
{
$my_sql_statement .=" column_b ";
};
$my_sql_statement .= "from ".$table_to_search_in
$where = " where column_b=2";
$my_sql_statemenet .=$where;
mysq_query($my_sql_statement);