i want to include a else statement after the completion of the block after the second if for category equal to helathcare ....now i want another else for finance but i am not getting where excatly to place that else
i have a confusion on where to keep the else for finance and 2 more categories
now whenever i try to place the one else at the last goes unrecable to its if statement i donno its very confusing as to where to place 2 more else if statments for 2 more categories
<?php
global $row2;
if(isset($_POST['category']))
{
if($_POST['category']== 'Healthcare')
{
$query = "select *from event where category = 'Healthcare';";
$result=mysqli_query($conn,$query)or die(mysqli_error($conn));
while($row2= mysqli_fetch_array($result))
{
?>
<div class="events events-full event-list">
<div class="container">
<div class="row">
<div class="col-md-9 col-sm-8">
<!--Blog Post Start-->
<div class="blog-post">
<div class="post-thumb">
<div class="link-wrap"> <i class="fa fa-search"></i> <i class="fa fa-link"></i> </div>
<img src="images/gallery/<?php echo $row2['event_image']?>" alt='user'></div>
<div class="event-text">
<div class="event-counter"></div>
<h4> <?php echo($row2['title']); ?> </h4>
<p><?php echo($row2['descrption']); ?></p>
<p><span class="glyphicon glyphicon-map-marker"><?php echo($row2['location']); ?></span></p>
<p><span class="glyphicon glyphicon-grain"><?php echo($row2['organizer']); ?></span></p>
<a class="nd" href="">
<form action="eventdetail.php" method="post">
<input type='hidden' value="<?php echo $row2['id']; ?>" name='id'/>
<button type="submit" class="btn btn-primary" name="detail" value=”detail”>Event Detail</button>
</div>
</a> </div>
</div>
</form>
<!--Blog Post End-->
<?php }
}
}
else
{
global $row2;
$query = "select *from event;" ;
$result=mysqli_query($conn,$query)or die(mysqli_error($conn));
while($row2= mysqli_fetch_array($result))
{
?>
<div class="events events-full event-list">
<div class="container">
<div class="row">
<div class="col-md-9 col-sm-8">
<!--Blog Post Start-->
<div class="blog-post">
<div class="post-thumb">
<div class="link-wrap"> <i class="fa fa-search"></i> <i class="fa fa-link"></i> </div>
<img src="images/gallery/<?php echo $row2['event_image']?>" alt='user'></div>
<div class="event-text">
<div class="event-counter"></div>
<h4> <?php echo($row2['title']); ?> </h4>
<p><?php echo($row2['descrption']); ?></p>
<p><span class="glyphicon glyphicon-map-marker"><?php echo($row2['location']); ?></span></p>
<p><span class="glyphicon glyphicon-grain"><?php echo($row2['organizer']); ?></span></p>
<a class="nd" href="">
<form action="eventdetail.php" method="post">
<input type='hidden' value="<?php echo $row2['id']; ?>" name='id'/>
<button type="submit" class="btn btn-primary" name="detail" value=”detail”>Event Detail</button>
</div>
</a> </div>
</div>
</form>
<!--Blog Post End-->
<?php } } ?>
?>
You can't put multiple else blocks along with the if block. However, you can use multiple(as many as you want) elseif/else if blocks along with the if block, like this:
if($_POST['category'] == 'Healthcare'){
...
}elseif($_POST['category'] == 'Finance'){
...
}elseif($_POST['category'] == '...'){
...
}else{
...
}
Here's the reference: http://php.net/manual/en/control-structures.elseif.php
Part of your problem seems to be poor formatting. If you lined up your open and close tags for your if statements I think you would be able to see this better. Having said that, you can add any elseif/if clauses for the category if where I marked below:
<!--Blog Post End-->
<?php
} // closes while loop
} else{ } // closes healthcare if, add extra else here
} // closes POST if
else
{
Related
I have a page of a website which has bootstrap cards on. The cards are generated dynamically, but I wanted to add a filter section. I am trying to use AJAX to acheive this, I have got to a point where when you select a checkbox it triggers the loader gif but then that loader gif doesn't disapear. Through my hours of debugging I can see that its the page that the AJAX call is calling that is the problem, but I just can't see what the issue is and I am not getting errors or anything in the console.
If anyone has any ideas I would really appreciate it, I have pasted my code below, also I am aware my sql queries are currently open to injection, just want to get it to work first.
<body>
<?php include("PHP/header.php"); ?>
<div class="container-fluid">
<div class="container" style="margin-top: 2%; text-align: center;">
<h1>Title goes here</h1>
Some tetx
<br/>
<br/>
<br/>
Filter Reviews:
<ul class="list-group">
<?php
$search = $conn->prepare("SELECT DISTINCT reviewcat FROM review_db ORDER BY reviewcat");
$search->execute();
while ($row = $search->fetch(PDO::FETCH_ASSOC)) {
?>
<li class="list-group-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input product_check" value="<?=$row['reviewcat'];?>" id="reviewcat"> <?=$row['reviewcat']; ?>
</label>
</div>
</li>
<?php } ?>
</ul>
</div>
<br/><br/>
<div class="row-fluid ">
<h5 class="text-center" id="textChange"> All Products </h5>
<hr>
<div class="text-center">
<img src="Images/loader.gif" id="loader" width="100" style="display: none">
</div>
<div id="result" class="card-deck card_group_style pt-4" >
<?php
$res_data = $conn->prepare("SELECT * FROM review_db");
$res_data->execute();
?>
<?php while ($row = $res_data->fetch(PDO::FETCH_ASSOC)) {// Important line !!! Check summary get row on array .. ?>
<div class="col-sm-6 col-lg-3 py-2">
<div class="card mb-4">
<img class="card-img-top card-images " src="Images/Reviews/<?php echo $row['reviewimage1'];?>" alt="<?php echo $row['reviewtitle'];?>" >
<div class="card-body">
<h5 class="card-title"><?php echo $row['reviewtitle'];?></h5>
<p class="card-text"><?php echo $row['reviewsynop'];?></p>
<a href="Reviews/review-content.php?id=<?php echo $row['id'];?>&reviewtitle=<?php echo $row['reviewtitle'];?>" class="btn btn-primary my-4" >Read More</a>
<div class="card-footer" style="padding: 1%;">
<small class="text-muted">Submitted: <?php
$my_date = $row['reviewsub'];
$date = DATE("d/m/Y",strtotime($my_date));
echo $date;?></small>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php include("PHP/footer.php"); ?>
</div>
</body>
<?php include("PHP/js.php"); ?>
<script>
$(document).ready(function(){
$('#link-review,#link-footer-review').addClass('active');
});
</script>
<script type="text/javascript">
$(document).ready(function(){
function get_filter_text(text_id){
var filterData = [];
$('#'+text_id+':checked').each(function(){
filterData.push($(this).val());
});
return filterData;
}
$(".product_check").click(function(){
$("#loader").show();
var action = 'data';
var reviewcat = get_filter_text('reviewcat');
$.ajax({
method:'POST',
url:'reviewaction.php',
data:{action:action,reviewcat:reviewcat},
success:function(response){
$("#result").html(response);
$("#loader").hide();
$("#textChange").text("Filtered Reviews");
}
});
});
});
</script>
</html>
reviewaction.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once $_SERVER['DOCUMENT_ROOT'] . '/Private/db.php';
// $stmt = $conn->prepare("SELECT * FROM blogdata ORDER BY blogsub DESC");
// $stmt->execute();
?>
<?php
if(isset($_POST['action'])){
$sql = "SELECT * FROM review_db WHERE reviewcat !=''";
$revsearch = $conn->prepare($sql);
$revsearch->execute();
$output='';
if($revsearch->num_rows>0){
while ($row = $revsearch->fetch(PDO::FETCH_ASSOC)) {
$output .= '
<div class="col-sm-6 col-lg-3 py-2">
<div class="card mb-4">
<img class="card-img-top card-images " src="Images/Reviews/'. echo $row['reviewimage1'];.'" alt="'. echo $row['reviewtitle'];.'" >
<div class="card-body">
<h5 class="card-title">'. echo $row['reviewtitle'];.'</h5>
<p class="card-text">'. echo $row['reviewsynop'];.'</p>
<a href="Reviews/review-content.php?id='. echo $row['id'];.'&reviewtitle='. echo $row['reviewtitle'];.'" class="btn btn-primary my-4" >Read More</a>
<div class="card-footer" style="padding: 1%;">
<small class="text-muted">Submitted: '.
$my_date = $row['reviewsub'];
$date = DATE("d/m/Y",strtotime($my_date));
echo $date;.'</small>
</div>
</div>
</div>
</div>
';
}
else{
$output = "<h3>No Reviews Found!</h3>";
}
echo $output;
}
?>
I have actually found something in the server error log, I was stupidly only use dev tools on firefox, but have found that in the reviewaction.php script I had left semicolons in and had also missed a closing bracket. There are still some other problems, which I can fix, just couldn't work out why it wasn't firing.
code i have written below is working fine but at the end of the looping the div is not closed its still opening a loop
<div class="carousel-inner">
<div class="item active">
<div class="row">
<?php
$recent_projects_sql="SELECT * from recent_projects where service_type='upholstery'";
$recent_projects_conn=mysql_query($recent_projects_sql) or die(mysql_error());
$i=0; $split=0;
while($projects=mysql_fetch_array($recent_projects_conn)) {
$i++;
?>
<div class="col-sm-3">
<div class="col-item" style="">
<div class="photo-shadow"></div>
<div class="photo">
<img src="admin/assets/images/uploads/projects/<?php echo $projects['attachment1']; ?>" alt="User one">
</div>
<div class="info">
<div class="name">
<?php echo $projects['service_name']; ?>
</div>
<div class="degination">
<?php echo $projects['sub_title']; ?>
</div>
<div class="buttons">
<a class="btn btn-theme ripple-effect" href="#">View More</a>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<?php
$split++;
if ($split % 4 == 0){
echo '</div></div><div class="item"><div class="row">';
}
}
?>
</div>
</div>
The Div has splited very well but in end of the loop div has not been closed. Thats only the problem please provide me the help to sort out the problem
When I inspect the element the last loop will show at the given result as follows:
<div class="col-sm-3">
<div class="col-item">
<div class="photo-shadow"></div>
<div class="photo">
<img src="admin/assets/images/uploads/projects/1557301934.jpg" alt="User one">
</div>
<div class="info">
<div class="name">UPHOLSTERY</div>
<div class="degination">UPHOLSTERY</div>
<div class="buttons">
<a class="btn btn-theme ripple-effect" href="#">View More</a>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div></div><div class="item"><div class="row">
I want to remove the two opening div's as dynamically. How can i set this to remove opened div's at then end of the looping
I just took a quick look and it looks like you are not closing the "carousel-inner" div
<div class="carousel-inner">
<div class="item active">
<div class="row">
<?php
$recent_projects_sql = "SELECT * from recent_projects where service_type='upholstery'";
$recent_projects_conn = mysql_query( $recent_projects_sql ) or die( mysql_error() );
$i = 0;
$split = 0;
while ( $projects = mysql_fetch_array( $recent_projects_conn ) ) {
$i ++;
?>
<div class="col-sm-3">
<div class="col-item" style="">
<div class="photo-shadow"></div>
<div class="photo">
<img src="admin/assets/images/uploads/projects/<?php echo $projects['attachment1']; ?>"
alt="User one">
</div>
<div class="info">
<div class="name">
<?php echo $projects['service_name']; ?>
</div>
<div class="degination">
<?php echo $projects['sub_title']; ?>
</div>
<div class="buttons">
<a class="btn btn-theme ripple-effect" href="#">View More</a>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<?php $split ++;
if ( $split % 4 == 0 ) {
echo '</div></div><div class="item"><div class="row">';
}
}
?>
</div>
</div>
Add a Boolean check for the execution of loop, such as $check = true;, add this within the loop.
after the loop add this
if($check){
echo " </div></div>";
}
That's because at the end of iteration (in case of mod 4 and even without it), you keep 2 divs opened
echo '</div></div><div class="item"><div class="row">';
I am working on a project where I came across where when I click plus sign the data will hide and the appear in the div next to it.
here is the code:
<fieldset class="col-md-4" >
<legend>Services</legend>
<div class="col-md-12" >
<?php
$id = 0;
foreach ($servicesname as $val) {
$id++;
?>
<div class="col-md-12" style="font-size: 16px;" id="itemservices<?php echo $id ?>">
<span style="float:left;" ><?php echo $val[0]['servicename']; ?></span>
<a style="float:right;" href onclick="return addSrvToCart('itemservices<?php echo $id ?>')" >
<strong>₹ <?php echo $val[0]['amount']; ?></strong>
<span class="glyphicon glyphicon-plus-sign" id="id_<?php echo $id; ?>"></span>
</a>
</div>
<?php } ?>
</div>
</fieldset>
and the code for next div:
<fieldset class="col-md-4" >
<legend>Cart</legend>
<div style="list-style:none;" class="no-left-padding" id="cart">
<div class="col-md-12" >
</div>
</div>
<div class="col-sm-12 no-right-padding" style="background-color:#f3f0f0; padding-top:6px; border:1px solid#ccc">
<label class="pull-right">/*what should i write here to show the sum */: ₨ </label>
</div>
<button style="margin-top:10px;" class="btn btn-primary btn-sm pull-right" onclick="bookNowAfterFilter()">Book Now</button>
</fieldset>
And This the Jquery code:
<script>
function addSrvToCart(elem){
alert($('#' + elem).html());
$('#' + elem).hide();
//return false;
//what should i write here the show that hidden div
document.getElementById('summery);
return false;
}
</script>
This is the picture and I want to display the data in the Cart div and show the amount
You need to change in both HTML and Script to achieve the result
Try like this
HTML
<fieldset class="col-md-4" >
<legend>Services</legend>
<div class="col-md-12" >
<?php
$id = 0;
foreach ($servicesname as $val) {
$id++;
?>
<div class="col-md-12" style="font-size: 16px;" id="itemservices<?php echo $id ?>">
<span style="float:left;" ><?php echo $val[0]['servicename']; ?></span>
<a style="float:right;" onclick=" addSrvToCart('itemservices<?php echo $id ?>')" >
₹<strong> <?php echo $val[0]['amount']; ?></strong>
<span class="glyphicon glyphicon-plus-sign" id="id_<?php echo $id; ?>"></span>
</a>
</div>
<?php } ?>
</div>
</fieldset>
and the code for next div:
<fieldset class="col-md-4" >
<legend>Cart</legend>
<div style="list-style:none;" class="no-left-padding">
<div class="col-md-12" id="cart" >
</div>
</div>
<div class="col-sm-12 no-right-padding pull-right" style="background-color:#f3f0f0; padding-top:6px; border:1px solid#ccc">
Total: ₨ <label class="" id="sumAmount">0</label>
</div>
<button style="margin-top:10px;" class="btn btn-primary btn-sm pull-right" onclick="bookNowAfterFilter()">Book Now</button>
</fieldset>
Script:
function addSrvToCart(elem){
var div=$('#' + elem);
div.hide();
$('#cart').append(div.html());
var total = parseInt(div.find('strong').html()) + parseInt($('#sumAmount').html());
$('#sumAmount').html(total);
}
It will produce output as
I think it will help you.
I am using bootstrap 3 and I am making a social networking site, this code here is a part of a panel which shows the posts.The problem is it is showing the comments on toggle but the comments are not appearing within the footer it is crossing it...So what is wrong in my or how can I extend the panel footer?
Here's the code:
<div class="panel-footer">
Like <span class="glyphicon glyphicon-thumbs-up"></span>
Comments
<div id='toggleComment<?php echo $idp;?>' style="display:none;">
<form action="" method="POST"><!--FORM COMMENT-->
<div class="form-group">
<div class="rows" >
<div class="col-sm-1" style="padding-right:2px;">
<div class="compic">
<img src="<?php echo $profilepic; ?>" style="width:100%;height:100%;" />
</div>
</div>
<div class="col-sm-11" style="padding-left:3px; padding-bottom:7px">
<textarea class="form-control expandable pull-left" name="comment<?php echo $idp;?>" id="comment" placeholder="Write a comment..." required>
</textarea>
</div>
</div>
<hr>
<button type="submit" class="btn btn-primary pull-right" name="subcom<?php echo $idp;?>"><b>Comment</b></button>
<div class="clearfix"></div>
</div></form>
<div class="rows" >
<?php
$postid=$idp;
$postby=$id;
$postto=$uid;
if(isset($_POST['subcom'.$postid]))
{ $postbody=$_POST['comment'.$postid];
if($postbody!="")
{$res=mysqli_query($con,"INSERT INTO comment VALUES('','$postby','$postto','$postbody','$postid')");}
}
$show=mysqli_query($con,"SELECT * FROM comment WHERE postid='$idp' ORDER by id");
while($show_row=mysqli_fetch_array($show))
{
$commentbyid=$show_row['cby'];
$combody=$show_row['cbody'];
$cbyquery=mysqli_query($con,"SELECT * FROM user WHERE id='$commentbyid'") or die(mysqli_error($con));
$cby=mysqli_fetch_array($cbyquery);
$cpic=$cby['profpic'];
if ($cpic== "" || !file_exists("userdata/profile_pics/$cpic"))
{
$cpic = "images/default_pic.jpg";
}
else
{
$cpic = "userdata/profile_pics/".$cpic;
}
$cname=ucfirst(strtolower($cby[1]));
$csname=ucfirst(strtolower($cby[2]));
?>
<div class="col-sm-1" style="padding-right:2px;">
<div class="compic">
<img src="<?php echo $cpic; ?>" style="width:100%;height:100%;" />
</div>
</div>
<div class="col-sm-11" style="padding-left:3px;">
<?php echo $cname." ".$csname;?><br>
<?php echo $combody;?>
</div>
<?php
}
?></div>
</div><!--Toggle Ends here-->
</div>
finally got it it was because of the <div class="clearfix"></div> and it got solved when I used it just after </div><!--Toggle Ends here-->
I have this code snippet that is failing to work, don't know what am doing wrong, am getting content from MYSQL database and using if else statement with while loop to echo the contents.
<?php
if ($row_item['cat_item_id'] == ''){
echo '<div class="col-sm-6 col-md-3"">
</p>
<p>
No Item To Show
</p>
</div>
</div>';
}
else {
while ($row_item = mysql_fetch_assoc($item)){
echo
'
<div class="col-sm-6 col-md-3" style="'.$row_item['display'].'">
<div class="thumbnail">
<img src="myaccount/user_data/'.$row_item['file_name'].'" />
</div>
<div class="caption">
<h3>'.$row_item['item_name'].'</h3>
<p>
<a href="item_detail.php?item='.$row_item['cat_item_id'].'" class="btn btn-primary" role="button">
View Item
</a>
<a href="contact_seller.php?contact='.$row_item['cat_item_id'].'" class="btn btn-default" role="button">
Contact Owner
</a>
</p>
</div>
</div>';
}
}
?>
Help me figure out what am not doing right.
You have to call while ($row_item = mysql_fetch_assoc($item))
first place.
Otherwise the $row_items doesn't get initialized properly.
So you put all inside
while ($row_item = mysql_fetch_assoc($item))
And check for the if-else conditions inside the while:
if ($row_item['cat_item_id'] == '') // this goes inside the while. Otherwise $row_item is not initialized properly
You are checking if
if ($row_item['cat_item_id'] == ''){
before you actually call
while ($row_item = mysql_fetch_assoc($item)){
To get $row_item
Try changing it to something like this:
while ($row_item = mysql_fetch_assoc($item)){
if ($row_item['cat_item_id'] == ''){
echo '<div class="col-sm-6 col-md-3"">
</p>
<p>No Item To Show</p></div></div>';
}else {
echo
'
<div class="col-sm-6 col-md-3" style="'.$row_item['display'].'">
<div class="thumbnail">
<img src="myaccount/user_data/'.$row_item['file_name'].'" />
</div>
<div class="caption">
<h3>'.$row_item['item_name'].'</h3>
<p>
<a href="item_detail.php?item='.$row_item['cat_item_id'].'" class="btn btn-primary" role="button">
View Item
</a>
<a href="contact_seller.php?contact='.$row_item['cat_item_id'].'" class="btn btn-default" role="button">
Contact Owner
</a>
</p>
</div>
</div>';
}
}
Try mysql_fetch_array
while ($row_item = mysql_fetch_array($item)){
echo
'
<div class="col-sm-6 col-md-3" style="'.$row_item['display'].'">
<div class="thumbnail">
<img src="myaccount/user_data/'.$row_item['file_name'].'" />
</div>
<div class="caption">
<h3>'.$row_item['item_name'].'</h3>
<p>
<a href="item_detail.php?item='.$row_item['cat_item_id'].'" class="btn btn-primary" role="button">
View Item
</a>
<a href="contact_seller.php?contact='.$row_item['cat_item_id'].'" class="btn btn-default" role="button">
Contact Owner
</a>
</p>
</div>
</div>';
}