A lot of the SQL code is duplicated as well.
if ( $request->getRequestMethod() == REQUEST_POST )
{
$sql = "SELECT * FROM $table_select
WHERE (inv_date <= '" . $request->getParam("inv_date2"). "' AND inv_date >= '" . $request->getParam("inv_date"). "')";
if ($request->getParam("brand") != null )
{
$sql .= " AND brand='".$request->getParam("brand")."'";
if($request->getParam("groups") != null)
{
$sql .= " AND groups='".$request->getParam("groups")."'";
if($request->getParam("engine_no") != null)
{
$sql .= " AND engine_no='".$request->getParam("engine_no")."'";
}
}
}
elseif ($request->getParam("groups") != null)
{
$sql .= " AND groups='".$request->getParam("groups")."'";
}
else
{
$sql .= " AND stat<>'1'";
}
}
Which bits of the code get run in which situations?
if ($request->getParam("brand") != null )
{
// brand!=null
if($request->getParam("groups") != null)
{
//brand!=null && groups!=null
if($request->getParam("engine_no") != null)
{
//brand!=null && groups!=null && engine_no!=null
}
}
}
elseif ($request->getParam("groups") != null)
{
// brand==null && groups!=null
}
else
{
// brand==null && groups==null
}