Hiding a Div Using PHP

Show Hide div if, if statement is true

You can use css or js for hiding a div. In else statement you can write it as:

else{
?>
<style type="text/css">#divId{
display:none;
}</style>
<?php
}

Or in jQuery

else{
?>
<script type="text/javascript">$('#divId').hide()</script>
<?php
}

Or in javascript

else{
?>
<script type="text/javascript">document.getElementById('divId').style.display = 'none';</script>
<?php
}

How to show and hide div based on php condition

Instead of putting the JavaScript code inside your PHP, just put the divs in there.

<?php
session_start();
?>

<li>

<?php
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) {
?>

<div style="float:right;display:block;" id="loggedin">
<a href="login_signup/login.php" class="myButton"> Loggedin </a>
</div>

<?php
} else {
?>

<div style="float:right;display:block;" id="public">
<a href="login_signup/login.php" class="myButton"> Login </a>
</div>

<?php
}
?>

</li>

Hiding a Div using php

Using Php in your CSS (Cascade Style Sheet) is not "proper",

Also, You can use Php in your HTML:

<body>
<?php if (condition){ ?>
<div id="content">
Foo bar
</div>
<?php } ?>
</body>

With this code, div block don't appear, (and you don't use it with JavaScript), You can use this for just hidden your div :

 <body>
<div id="content" <?php if (condition){ echo 'style="display:none;"'; } ?>>
Foo bar
</div>
</body>

HIde a div with a PHP echo statement with CSS

There are some good php libraries that can detect whether the user is on their phone or on a desktop. You can then use this to control which nav is used.

Example using http://mobiledetect.net/

include 'Mobile_Detect.php';
$md = new Mobile_Detect();

if($md->isMobile()){
echo '<span class="paginationMini">' . $paginationCtrlsMob . '</span>';
}else{
echo '<span class="paginationFull">' . $paginationCtrls . '</span>';
}

display:none should work regardless of whether you have an echo statement inside the <span> tag. The only explanation as to why its not working in your case is if the php variables contain tags that aren't properly closed.

How to hide a Div using PHP

Update from your posted code:

For one, you are using $SESSION instead of $_SESSION. Second, you are setting $SESSION['name'] using a single equal sign, so the if condition would always fail because it is evaluating if (NULL). You need to use == or ===. Read up on comparison operators.


<?php
if (condition) {
?>
<div></div>
<?php
}
?>

Hiding a div if property is equal to one in php

Change your code condition with following.

<?php session_start();
include 'db.php';
$id = (int)$_GET['id'];
$sql = "SELECT * FROM tbl_properties WHERE property_id = $id";
$oppointArr =array();
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$oppointArr = $row;
}
}
else
{
echo "0 results";
}
$display = 'block';
if(($oppointArr['property_type'])=='Open-Plots'){
$display = 'none';
}
?>

<input type='hidden' value='<?=$id;?>' name='property_id'>
<div class="property-specs">
<ul class="specs-list">
<li><div class="icon"><span class="flaticon-double-king-size-bed"></span></div> <?php echo $oppointArr['property_type'];?></li>
<li><div class="icon"><span class="flaticon-copy"></span></div> <?php echo $oppointArr['area_sqft'];?> Sqft</li>
<li><div class="icon"><span class="fa fa-compass"></span></div> <?php echo $oppointArr['facing'];?> Facing</li>
<li id="car_parking" style="display:<?php echo $display?>">><div class="icon"><span class="flaticon-private-garage"><?php echo $oppointArr['car_parking'];?></span></div></li>
<li id="total_bathrooms"><div class="icon"><span class="flaticon-vintage-bathtub"></span></div> <?php echo $oppointArr['total_bathrooms'];?> Bathrooms</li>
</ul>
</div>

Show/hide Div Dynamically in PHP

Try this code.

<?php
$sets = array('one','two','three','four');
?>
<script stype="textjavascript">
var current = 0;
var total = <?php echo count($sets); ?>;
function test() {
for(var i=0;i<total;i++)
{
document.getElementById("set"+i).style.display="none";
}
current++;
document.getElementById("set"+current).style.display="block";
}
</script>
<?php
foreach($sets as $key=>$set){
?>
<div <? if($key>0){ ?> style="display: none" <? } ?> id="set<?php echo $key; ?>">
== <?php echo $set; ?> ==
<p><a class="continue" href="#" onclick="test()">Continue</a></p>
</div>
<?php } ?>


Related Topics



Leave a reply



Submit