All the PHP code is in the post loop so when adding a new post it gets also the buttons and when pressing one button it opens all buttons and containers
<div class="col-sm-1 ">
<span class="btn btn-sm album-song">
<a class="btn btn-sm show-album-song">⋁</a>
<a class="btn btn-sm hide-album-song">⋀</a>
</span>
</div>
<div class="container album-songs-show-hide">
<div class="row">
<div class="col-sm-4 name"><?php _e('Song Name', 'koband');?></div>
<div class="col-sm-4"><?php _e('Song Length', 'koband');?></div>
<div class="col-sm-4"><?php _e('Song Details', 'koband');?></div>
</div>
<div class="row" style="background-color: #d6d6d6; border-bottom: 1px solid #000;">
<?php foreach ($album_song_details[0] as $value_song_details) { ?>
<div class="col-sm-4"><?php echo $value_song_details['name-details']; ?></div>
<div class="col-sm-4"><?php echo $value_song_details['length']; ?></div>
<div class="col-sm-4"><?php echo $value_song_details['detail']; ?></div>
<?php } ?>
</div>
</div>
and the jQuery code goes here
$(".album-songs-show-hide").hide();
$(".hide-album-song").hide();
$(".show-album-song").click(function(){
$(this).find(".album-songs-show-hide").slideDown(1000);// show container elements
$(".show-album-song").hide(); // button down hide
$(".hide-album-song").show(); // button up show
});
Thanks to all for commenting solutions but for me this was the working solution for you
$(".album-songs-show-hide").hide();
$(".hide-album-song").hide();
$(".show-album-song").click(function(){
$(this).closest("div.container").find(".album-songs-show-hide").slideDown(1000);// hide container elemnts
$(".show-album-song").hide(); // button down hide
$(".hide-album-song").show(); // button up show
});
Related
Hi I am working on a project that use bootstrap. I have edit button and that button sends a get request. What I want to do is send that GET request and get it from the bootstrap off-canvas. My off-canvas opens with data-bs-target. Any help?
edit_album_item is the page where off-canvas included
My main page:
<?php include "includes/edit_album_item.php" ?>
<div class="col-md-4" style="margin-top: 20px;">
<div class="card">
<div class="row" style="position: absolute;">
<div class="col-md-4">
<button class="btn btn-danger delete-card"><i class="fa-solid fa-trash"></i></button>
</div>
<div class="col-md-6">
<button class="btn btn-warning delete-card"><i class="fas fa-edit"></i></button>
</div>
</div>
<img src="includes/images/<?php echo $item_image ?>" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title"><?php echo $item_title ?></h5>
<p class="card-text"><?php echo $item_description ?></p>
</div>
</div>
</div>
Actually the edit_album_item.php is not well developed yet. I want send a get request and open off-canvas get the information from the get request. Thanks in advance!
Example Image
I understand your question. To do this what you need to do is,
add anchor to your edit button to send get request like this
index.php?yourreq
and try this is on the bottom of your page
if(isset($_GET['your req'])) {
echo '
<script>
$("#offcanvasAlbumItem").modal("show");
</script>
';
}
I think now you are good to go.
I'm trying to make an accordion for each row in the database using the Foreach loop
I tried this but I'm getting only one accordion out its supposed to make more than 2 accordion deppending on rows count this what i have tried :-
<?foreach ($fetchedDrafts as $draft):?>
<div id="<?=$draft['name'];?>" role="tablist" class="border border-danger rounded" aria-multiselectable="true">
<div class="card">
<div class="card-header" role="tab" style="height:120px !important;" id="section1HeaderId">
<h5 class="mb-0">
<a data-toggle="collapse" data-parent="#accordianId" href="#section1ContentId" aria-expanded="true" aria-controls="section1ContentId">
<center>
<!---->
<button type="button" class="btn btn-warning pill" style="display:none;"><?$draft['name'];?></button>
<h3 class="Title" style="display:none;font-family:hana;"></h3>
</center>
<img class="accordianimg pull-left" style="width:180px; height:120px;" src="..\upload\gsk.png" alt="alt"></img>
</a>
<div class="input-container" style="margin-top:2rem !important; margin-right:6rem;">
<h2>
<button onclick="funvction()" class="btn btn-danger SearchButton"style="font-family:hana;">بحث</button>
<input class="border border-danger rounded SearchInput" type="text" style="width:440px;"id="SearchInput" placeholder="البحث عن المنتج" name="DraftSearchFiled" onchange="DraftSearch()">
</h2>
</div>
</div><br>
<div id="section1ContentId" class="collapse in" role="tabpanel" aria-labelledby="section1HeaderId" style="overflow-x: hidden !important;" onscroll="">
<div class="card-body d-flex flex-wrap">
<div class="row justify-content-center">
<div id="demo" class="carousel slide carousel" data-ride="carousel" style="margin-left:20rem;width: 26rem; height:31rem;">
<!-- no need for indicators -->
<div class="carousel-inner canner">
<?
$i = 0;
foreach($DRTitems as $row){
$actives = '';
if($i == 0){
$actives ='active';
}
?>
<div class="carousel-item <?= $actives;?>">
<div class="container">
<div class="row justify-content-center">
<div class="card" style="width: 26rem; height:auto;">
<? if($row['Sale'] == true){
echo'<div class="corner-ribbon top-left sticky shadow">تخفيض</div>';
}else{
echo'<div class="corner-ribbon top-left-green sticky shadow">افضل سعر</div>';
}
?>
<img class="card-img-top" src="<?= $row['imageurl'] ?>" alt="Drug" style=""></img>
<div class="card-body body">
<h1 class="card-title Productname " style="font-family:Tahoma !important; font-size:42px !important;"><?= $row['name'] ?></h1><br><br><br>
<p class="chemicalcom"><?= $row['chemicalcom']?></p><br>
<p class="price"><?= $row['price'] ?>$</p>
<input type="submit" class="btn btn-success btn-sm btn-block btn" value="أضف للسلة"></input>
</div>
</div>
</div>
</div>
</div>
<? $i++; }?>
</div>
<?php endforeach; ?>
what i have in db is 3 rows but the code makes only one accordion
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.
Using php and mysql and bootstrap.
The php and mysql works fine but for the bootstrap, if i am actually calling values from
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
im getting all rows in a given div but if i want to use bootstrap collapse
<button data-toggle="collapse" data-target="#demo">More info</button>
<div id="demo" class="collapse">
<div id="chart_div" style="width: 100%; height: 300px;"></div>
</div>
Since the id of the div will be the same, only 1 will collapse if theres more than 1 row. Even if i used modal, when clicking on the button to display to modal, only for the first value will display
<?php
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)){?>
<div class="w3-container w3-card-2 w3-white w3-margin-bottom">
<div class="w3-container">
some stuff`
<button data-toggle="collapse" data-target="#demo">More info</button>
<div id="demo" class="collapse">`
<div id="chart_div" style="width: 100%; height: 300px;"></div>
</div>
</div>
</div>
<?php }?>
The problem is for the button thanks
If you need unique ids for each row you can do this, for example:
<?php
$i = 0;
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
$current_id = 'id-' . $i;
$i++;?>
<div class="w3-container w3-card-2 w3-white w3-margin-bottom">
<div class="w3-container">
some stuff
<button data-toggle="collapse" data-target="#<?=$current_id?>">More info</button>
<div id="<?=$current_id?>" class="collapse">
<div id="chart_div" style="width: 100%; height: 300px;"></div>
</div>
</div>
</div>
<?php }?>
In this case you will have unique ids - id-0, id-1, id-2, etc. assigned to each item of your output.
Add data to data-target button attribute and id collapse div attribute to distinct each one.
JSFidlle based on your div
<div class="w3-container w3-card-2 w3-white w3-margin-bottom">
<div class="w3-container">
some stuff`
<button data-toggle="collapse" data-target="#demo">More info</button>
<div id="demo" class="collapse">`
<div id="chart_div" style="">0</div>
</div>
</div>
</div>
<div class="w3-container w3-card-2 w3-white w3-margin-bottom">
<div class="w3-container">
some stuff`
<button data-toggle="collapse" data-target="#demo1">More info</button>
<div id="demo1" class="collapse">`
<div id="chart_div" style="">1</div>
</div>
</div>
</div>
<div class="w3-container w3-card-2 w3-white w3-margin-bottom">
<div class="w3-container">
some stuff`
<button data-toggle="collapse" data-target="#demo2">More info</button>
<div id="demo2" class="collapse">`
<div id="chart_div" style="">2</div>
</div>
</div>
</div>
I'm trying to make a page that gets entries from a database and displays them in a <div> called "gallery-item". However the lightbox works, it only shows the first entry of the database. I hope someone can make sense of this code and may be able to help me with my problem.
My html/php/sql
<?php if (isset($_POST["Website"])) {
$query=$db->prepare("SELECT * FROM `portfoliodb`.`website`");
$query->execute();
while ( $row = $query->fetch()){
$website_id = $row['website_id'];
$website_name = $row ['website_name'];
$website_desc_en = $row ['website_desc_en'];
$website_tags = $row ['website_tags'];
$website_image = $row ['website_image'];
$website_type = $row['website_type'];
echo'
<div class="background hidden" id="background"></div>
<a>
<div class="lightbox hidden" id="lightbox">
<div class="box-title hidden" id="box-title">
<h4 class="hidden" id="box-title-h">' . htmlspecialchars($website_name) . '</h4>
<h4 class="close hidden" id="close">X</h4>
</div>
<div class="box-img hidden" id="box-img">
</div>
<div class="box-foot hidden" id="box-foot">
<div class="box-space hidden" id="box-space"></div>
<div class="box-desc hidden" id="box-desc">
<p class="desc-text hidden" id="box-text">'. htmlspecialchars($website_desc_en) .' </p>
</div>
<div class="tag-space-box hidden" id="box-tags-space"></div>
<div class="tag-box hidden" id="box-tags">
<small id="box-small" class="hidden">'. htmlspecialchars($website_tags) .'</small>
</div>
</div>
</div>
</a>
<a>
<div class="gallery-item-web button" id="button">
<p class="gallary-item-text">';
echo htmlspecialchars($website_name);
echo'</p>';
echo '<i class="fa fa-desktop fa-3x position-icon"></i>
</div></a>
';
}}
The gallery shows all entries in the database so that works fine, the only problem is that the lightbox shows the first entry, so if I were to have a database with the entries "Apples, Pears, Oranges", the gallery would display "Apples, Pears, Oranges". But the lightbox would display "Apples" on every single entry.
My Jquery
$(document).ready(function(){
$(".button").click(function(){
$("#background").toggleClass("hidden");
$("#lightbox").toggleClass("hidden");
$("#box-title").toggleClass("hidden");
$("#box-title-h").toggleClass("hidden");
$(".close").toggleClass("hidden");
$("#box-img").toggleClass("hidden");
$("#box-foot").toggleClass("hidden");
$("#box-space").toggleClass("hidden");
$("#box-desc").toggleClass("hidden");
$("#box-text").toggleClass("hidden");
$("#box-tags-space").toggleClass("hidden");
$("#box-tags").toggleClass("hidden");
$("#box-small").toggleClass("hidden");
});
$(".close").click(function(){
$("#background").toggleClass("hidden");
$("#lightbox").toggleClass("hidden");
$("#box-title").toggleClass("hidden");
$("#box-title-h").toggleClass("hidden");
$(".close").toggleClass("hidden");
$("#box-img").toggleClass("hidden");
$("#box-foot").toggleClass("hidden");
$("#box-space").toggleClass("hidden");
$("#box-desc").toggleClass("hidden");
$("#box-text").toggleClass("hidden");
$("#box-tags-space").toggleClass("hidden");
$("#box-tags").toggleClass("hidden");
$("#box-small").toggleClass("hidden");
});
$(".background").click(function(){
$("#background").toggleClass("hidden");
$("#lightbox").toggleClass("hidden");
$("#box-title").toggleClass("hidden");
$("#box-title-h").toggleClass("hidden");
$(".close").toggleClass("hidden");
$("#box-img").toggleClass("hidden");
$("#box-foot").toggleClass("hidden");
$("#box-space").toggleClass("hidden");
$("#box-desc").toggleClass("hidden");
$("#box-text").toggleClass("hidden");
$("#box-tags-space").toggleClass("hidden");
$("#box-tags").toggleClass("hidden");
$("#box-small").toggleClass("hidden");
});
});
(It's pretty bad I know, this is my first time using Jquery)
This is the Jquery for the lightbox, it toggles the class on every item of the lightbox to "hidden". Whih basically makes every item with that class invisible, great for a lightbox.
First off, you don't need to add class of "hidden" to every element. You can just add it to the container element and then all tags inside would also be hidden.
Your main mistake was to have the same ids and classes for all images, you will need to ensure that each image has an unique identifier.
Try my solution: https://jsfiddle.net/3vhv90ce/2/
HTML:
<div class="container1">
<div class="background" id="background"></div>
<a>
<div class="lightbox" id="lightbox">
<div class="box-title" id="box-title">
<h4 class="" id="box-title-h">name</h4>
<h4 class="close" id="close">X</h4>
</div>
<div class="box-img" id="box-img">
</div>
<div class="box-foot" id="box-foot">
<div class="box-space" id="box-space"></div>
<div class="box-desc" id="box-desc">
<p class="desc-text" id="box-text">description</p>
</div>
<div class="tag-space-box" id="box-tags-space"></div>
<div class="tag-box" id="box-tags">
<small id="box-small" class="">tags</small>
</div>
</div>
</div>
</a>
</div>
</div>
<div class="gallery-item-web button" data-id="1">
<p class="gallary-item-text">Click me</p>
<i class="fa fa-desktop fa-3x position-icon"></i>
</div>
<div class="container2">
<div class="background" id="background"></div>
<a>
<div class="lightbox" id="lightbox">
<div class="box-title" id="box-title">
<h4 class="" id="box-title-h">name</h4>
<h4 class="close" id="close">X</h4>
</div>
<div class="box-img" id="box-img">
</div>
<div class="box-foot" id="box-foot">
<div class="box-space" id="box-space"></div>
<div class="box-desc" id="box-desc">
<p class="desc-text" id="box-text">description</p>
</div>
<div class="tag-space-box" id="box-tags-space"></div>
<div class="tag-box" id="box-tags">
<small id="box-small" class="">tags</small>
</div>
</div>
</div>
</a>
</div>
</div>
<div class="gallery-item-web button" data-id="2">
<p class="gallary-item-text">Click me</p>
<i class="fa fa-desktop fa-3x position-icon"></i>
</div>
JS:
$(document).ready(function(){
$(".button").click(function(){
$('.container'+$(this).data('id')).toggleClass("hidden");
});
});
CSS:
.hidden {
display: none;
}
.gallery-item-web {
cursor: pointer;
}
I suppose your problem came from those lines:
<div class="background hidden" id="background"></div>
<div class="gallery-item-web button" id="button">
you have many controls with the same id, And this is ambiguous for jQuery.