$sql = "SELECT * FROM bid b
LEFT JOIN type t USING(type_id)
LEFT JOIN currency c USING(currency_id)
LEFT JOIN rate r USING(rate_id) WHERE t.type_name = :typeName";
$result = $db->prepare($sql);
$result->bindParam(':typeName', $_POST['type_name'], PDO::PARAM_STR);
$result->execute();
$sql = 'SELECT * FROM bid b
LEFT JOIN currency c USING(currency_id)
LEFT JOIN rate r USING(rate_id)'
. (isset($_POST['type_name'])? ' LEFT JOIN type t USING(type_id) WHERE t.type_name = :typeName': '');
$result = $db->prepare($sql);
if(isset($_POST['type_name'])) {
$result->bindParam(':typeName', $_POST['type_name'], PDO::PARAM_STR);
}
$result->execute();