if($parent_id_current > 0) {
$parent_id = $parent_id_current;
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$parent_id_current'";
$parent_id_current = $GLOBALS['db']->getOne($sql);
if($parent_id_current > 0) {
$parent_id = $parent_id_current;
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$parent_id_current'";
$parent_id_current = $GLOBALS['db']->getOne($sql);
if($parent_id_current > 0) {
$parent_id = $parent_id_current;
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$parent_id_current'";
$parent_id_current = $GLOBALS['db']->getOne($sql);
if($parent_id_current > 0) {
$parent_id = $parent_id_current;
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$parent_id_current'";
$parent_id_current = $GLOBALS['db']->getOne($sql);
if($parent_id_current > 0) {
$parent_id = $parent_id_current;
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$parent_id_current'";
$parent_id_current = $GLOBALS['db']->getOne($sql);
if($parent_id_current > 0) {
$parent_id = $parent_id_current;
}
}
}
}
}
}
} else {
$parent_id = 0;
}
I know this is bad practice .. but how to rewrite to a good function structure. I know the return will make this code more clean.. but I just don't know where to put it.