私は、約9つのパラメータに依存する条件付き検索を作成しています。今のところ、私は 4 しか使用していませんが、非常に大きくなり、維持するのに多忙になっています。コード行を短くして簡単に維持できるように、誰かが最善の方法を提案できますか? 以下は私のコードです
if($min_year=="Select" && $max_year=="") {
if($makes=='All' && $models=='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where vehicles.manufacturerID=models.manufacturerID and vehicles.modelID=models.modelID
and models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where vehicles.manufacturerID=models.manufacturerID and vehicles.modelID=models.modelID
and models.manufacturerID=manufacturers.manufacturerID");
} elseif($makes!='All' && $models=='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails,vehicles.* from models, manufacturers,
vehicles where models.manufacturerID=$makes and vehicles.manufacturerID=models.manufacturerID and
vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page
");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where models.manufacturerID=$makes and vehicles.manufacturerID=models.manufacturerID and
vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID");
} elseif($makes=='All' && $models!='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails,vehicles.* from models, manufacturers,
vehicles where vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID
LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID");
} elseif($makes!='All' && $models!='All Models' && $makes!='select' && $models!='select') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where models.modelID=$models and models.manufacturerID=$makes and vehicles.modelID=models.modelID
and models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where models.modelID=$models and models.manufacturerID=$makes and vehicles.modelID=models.modelID
and models.manufacturerID=manufacturers.manufacturerID");
} else {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models,
manufacturers, vehicles where vehicles.modelID=models.modelID and
models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers, vehicles
where vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID");
}
} elseif($min_year!="Select" && $max_year==""){
if($makes=='All' && $models=='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where vehicles.manufacturerID=models.manufacturerID and vehicles.year>=$min_year and
vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page
");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where vehicles.manufacturerID=models.manufacturerID and vehicles.year>=$min_year and
vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID");
} elseif($makes!='All' && $models=='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where models.manufacturerID=$makes and vehicles.manufacturerID=models.manufacturerID and
vehicles.year>=$min_year and vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID
LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where models.manufacturerID=$makes and vehicles.manufacturerID=models.manufacturerID and
vehicles.year>=$min_year and vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID
");
} elseif($makes=='All' && $models!='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where vehicles.modelID=models.modelID and vehicles.year>=$min_year and
models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where vehicles.modelID=models.modelID and vehicles.year>=$min_year and
models.manufacturerID=manufacturers.manufacturerID");
} else {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails,vehicles.* from models, manufacturers,
vehicles where models.modelID=$models and models.manufacturerID=$makes and vehicles.modelID=models.modelID
and vehicles.year>=$min_year and models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where models.modelID=$models and models.manufacturerID=$makes and vehicles.modelID=models.modelID
and vehicles.year>=$min_year and models.manufacturerID=manufacturers.manufacturerID");
}
} elseif($min_year=="Select" && $max_year!=""){
if($makes=='All' && $models=='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where vehicles.manufacturerID=models.manufacturerID and vehicles.year<=$max_year and
vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page
");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where vehicles.manufacturerID=models.manufacturerID and vehicles.year<=$max_year and
vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID");
} elseif($makes!='All' && $models=='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where models.manufacturerID=$makes and vehicles.manufacturerID=models.manufacturerID and
vehicles.year<=$max_year and vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID
LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where models.manufacturerID=$makes and vehicles.manufacturerID=models.manufacturerID and
vehicles.year<=$max_year and vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID
");
} elseif($makes=='All' && $models!='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where vehicles.modelID=models.modelID and vehicles.year<=$max_year and
models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where vehicles.modelID=models.modelID and vehicles.year<=$max_year and
models.manufacturerID=manufacturers.manufacturerID");
} else {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where models.modelID=$models and models.manufacturerID=$makes and vehicles.modelID=models.modelID
and vehicles.year<=$max_year and models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where models.modelID=$models and models.manufacturerID=$makes and vehicles.modelID=models.modelID
and vehicles.year<=$max_year and models.manufacturerID=manufacturers.manufacturerID");
}
} else {
if($makes=='All' && $models=='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where vehicles.manufacturerID=models.manufacturerID and vehicles.year<=$max_year and vehicles.year>=$min_year
and vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page
");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where vehicles.manufacturerID=models.manufacturerID and vehicles.year<=$max_year and vehicles.year>=$min_year
and vehicles.modelID=models.modelID and models.manufacturerID=manufacturers.manufacturerID");
} elseif($makes!='All' && $models=='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where models.manufacturerID=$makes and vehicles.manufacturerID=models.manufacturerID and
vehicles.year<=$max_year and vehicles.year>=$min_year and vehicles.modelID=models.modelID
and models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page ");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where models.manufacturerID=$makes and vehicles.manufacturerID=models.manufacturerID and
vehicles.year<=$max_year and vehicles.year>=$min_year and vehicles.modelID=models.modelID
and models.manufacturerID=manufacturers.manufacturerID");
} elseif($makes=='All' && $models!='All Models') {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where vehicles.modelID=models.modelID and vehicles.year<=$max_year and vehicles.year>=$min_year and
models.manufacturerID=manufacturers.manufacturerID LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where vehicles.modelID=models.modelID and vehicles.year<=$max_year and vehicles.year>=$min_year and
models.manufacturerID=manufacturers.manufacturerID");
} else {
$select = mysql_query("select models.modelID, models.manufacturerID, models.modelName, manufacturers.manufacturerID,
manufacturers.manufacturerName, manufacturers.manufacturerDetails, vehicles.* from models, manufacturers,
vehicles where models.modelID=$models and models.manufacturerID=$makes and vehicles.modelID=models.modelID
and vehicles.year<=$max_year and vehicles.year>=$min_year and models.manufacturerID=manufacturers.manufacturerID
LIMIT $start, $per_page");
$select_count = mysql_query("select count(vehicles.modelID) as count from models, manufacturers,
vehicles where models.modelID=$models and models.manufacturerID=$makes and vehicles.modelID=models.modelID
and vehicles.year<=$max_year and vehicles.year>=$min_year and models.manufacturerID=manufacturers.manufacturerID
");
}
}
ご覧のとおり、これらのループは長く複雑になっています。何か提案してください。前もって感謝します