mardi 7 mai 2019

Better way than multiple if?

A better way than multiple if condition in php? Is too many if condition there, so i need something more simple and efficient...and you can show me examples?!

if($_GET['id']=="4") { 
     try {
     $ids = '4,246,226';
     $notin = '1';
     $parent_forum = 'php_forums.parent_id';
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
                         }
}
if($_GET['id']=="246") { 
     try {
     $ids = '246';
     $notin = '1';
     $parent_forum = 'php_forums.parent_id';
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
                         }
}
if($_GET['id']=="226") { 
     try {
     $ids = '226';
     $notin = '1';
     $parent_forum = 'php_forums.parent_id';
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
                         }
}

Aucun commentaire:

Enregistrer un commentaire