Sunday, July 29, 2018

html - If and else statement in PHP inside of an echo





I want to give the admin the ability to activate the user account so I have to status active and inactive
When I run my code I get 4 status
Active
Inactive
Active

Inactive
You will find here a screenshot to understand the problem I’m facing



http://i.imgur.com/2c0VcN7.png



    if(isset($_GET['id_user'])){

include("conexion.php");

$rep=$db->query("select * from user WHERE id_user=" .$_GET['id_user'] );


while($l=$rep->fetch()){
echo "



























"; // fin echo
}
}
?>

Answer



Your code may not have been properly formed. Try this instead:



    

if( isset($_GET['id_user']) ){
include("conexion.php");
$rep = $db->query( "select * from user WHERE id_user=" . $_GET['id_user'] );

// YOU ARE FETCHING A SINGLE USER... NO NEED FOR A LOOP...
// JUST GET THE ARRAY OBJECT AND USE IT DIRECTLY...
$l = $rep->fetch();
?>


























No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...