How to solve the logic problem of this php code block?

Asked

Viewed 34 times

0

In this piece of code, I take what the url is sending and save the parameters in variáveis to subsequently pass them into a function.

if(isset($_GET['funcao']) && $_GET['funcao'] == 'lereresponder'){
    if (!empty($_GET['tipo']) && 
        !empty($_GET['funcao']) &&
        $_GET['funcao'] == 'lereresponder'){

        $id = $_GET['id'];
        $tipo = $_GET['tipo'];

        lerresponder($id, $tipo);

    }
}

In this next code that is function I am receiving the parameters with the intention of building a view through a database query using the captured parameters.

function lerresponder($id, $tipo){

    global $pdo;

    echo $id . '<br>';
    echo $tipo . '<br>';

}

Well, I’m getting the vestments from if(isset($_GET['funcao']) ... inside the function to make the query in the database.

Question 1: The way I’m passing these vestments to the Function seems right?

Question 2: How to call this function? So: lereresponder($id, $tipo)?

Piecing together the code and the file I call the function, repeat the instruction lerresponder($id, $tipo); 3 times and it bothered me.

Question 3: The way to write this code is correct?

  • Also add the part where you repeat the function 3 times.

  • I solved ... just put the if(isset($_GET['function']) && ... within the view instead of placing in the same Function and then have to call Function again in view.

  • Only problem of logic ... :)

  • you have two if nested that do the same checking, even one using isset() and the other empty(), use only the if from within

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.