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
JavaScript: How to Create Jsonp
Get First 100 Characters from String, Respecting Full Words
Twitter API Returns Error 215, Bad Authentication Data
Generating Facebook Open Graph Meta Tags Dynamically
PHP Read Sub-Directories and Loop Through Files How To
Deny Direct Access to All .PHP Files Except Index.PHP
How to Handle Ipv6 Addresses in PHP
Localhost Vs. 127.0.0.1 in MySQL_Connect()
Restructure Multidimensional Array of Column Data into Multidimensional Array of Row Data
Switch PHP Versions on Commandline Ubuntu 16.04
What Do the "=&" and "&=" Operators in PHP Mean
Download Files in Laravel Using Response::Download
PHP Get Site Url Protocol - Http VS Https
Difference Between Method Calls $Model-≫Relation(); and $Model-≫Relation;