This topic is locked
[SOLVED]

 Hiding Item Based on query on Login Page

3/17/2020 00:28:18
PHPRunner General questions
L
lcslouis author

here is my code in the Before Display on my Login Page.

I have tried multiple different variants but none will work.

I can hide the field without the If statement but I want to control it by the Database query.



$sql= DB::Query("SELECT * FROM [dbo].[settings] WHERE tablename='dbo.HSRREG_users'");

$data = $sql->value("visible");

If($data = 1)

{
$pageObject->showItem("snippet");

}

else if ($data = 0)

{
$pageObject->hideItem("snippet");

}


What do I need to do to fix this. The field shows no matter what code is running.

W
wpl 3/17/2020



here is my code in the Before Display on my Login Page.

I have tried multiple different variants but none will work.

I can hide the field without the If statement but I want to control it by the Database query.



$sql= DB::Query("SELECT * FROM [dbo].[settings] WHERE tablename='dbo.HSRREG_users'");

$data = $sql->value("visible");

If($data = 1)

{
$pageObject->showItem("snippet");

}

else if ($data = 0)

{
$pageObject->hideItem("snippet");

}


What do I need to do to fix this. The field shows no matter what code is running.


louisg,
at first sight, you are trying to assign 1 or 0 to $data. What you rather want to do is compare $data to 1 or 0. So you would write:



If($data == 1)

{
$pageObject->showItem("snippet");

}

else if ($data == 0)

{
$pageObject->hideItem("snippet");

}
L
lcslouis author 3/17/2020

Thanks I program in vb and other languages compare is normally just an = i didn't know that it uses compare as ==