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>
Related
I want to get the .text() of the sibling customerID from the class"db_record_left" when class="db_record_left" gets clicked.
The whole class="db_record" is dynamical generated. But the console.log(CustID); still prints it for every class="db_record" and not only for the clicked one.
echo'
<div class="db_record" id="potentialCustomer-'.$countPotentialCustomers.'">
<div class="db_record_left">
<div class="db_record_describer">'.$cus_Fname.' '.$cus_Lname.'</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Adresse:</div>
<div class="db_record_info">'.$cus_Adress.'</div>
<div class="db_record_info">
<span>'.$cus_ZipCode.' </span>
<span>'.$cus_Locality.'</span>
</div>
</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Fahrzeuge:</div>
'.matchVehicles($cus_Vehicles).'
</div>
</div>
<div class="db_record_right">
<div class="material-icons md-large md-ghost-white-enabeld w-embed">
<span class="material-icons-outlined">navigate_next</span>
</div>
</div>
</div>
<span class="customerID" style="display: none">'.$cus_ID.'</span>
';
This would be the jQuery-code
function checkCustomerInformation(){
$(".db_records_wrapper").on('click', 'div.db_record', function (){
const CustID = $(this).siblings(".customerID").text();
console.log(CustID);
});
}
siblings() gets every matching sibling element. To get only the only following the .db_record which was clicked, use next():
$(this).next(".customerID").text();
Here's a working example:
function checkCustomerInformation() {
$(".db_records_wrapper").on('click', 'div.db_record', function() {
const custID = $(this).next(".customerID").text();
console.log(custID );
});
}
checkCustomerInformation();
.db_record {
margin: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="db_records_wrapper">
<div class="db_record" id="potentialCustomer-'.$countPotentialCustomers.'">
<div class="db_record_left">
<div class="db_record_describer">$cus_Fname1 $cus_Lname1</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Adresse:</div>
<div class="db_record_info">$cus_Adress1</div>
<div class="db_record_info">
<span>$cus_ZipCode1</span>
<span>$cus_Locality1</span>
</div>
</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Fahrzeuge:</div>
matchVehicles($cus_Vehicles1)
</div>
</div>
<div class="db_record_right">
<div class="material-icons md-large md-ghost-white-enabeld w-embed">
<span class="material-icons-outlined">navigate_next</span>
</div>
</div>
</div>
<span class="customerID" style="display: none">$cus_ID1</span>
<div class="db_record" id="potentialCustomer-'.$countPotentialCustomers.'">
<div class="db_record_left">
<div class="db_record_describer">$cus_Fname2 $cus_Lname2</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Adresse:</div>
<div class="db_record_info">$cus_Adress2</div>
<div class="db_record_info">
<span>$cus_ZipCode2</span>
<span>$cus_Locality2</span>
</div>
</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Fahrzeuge:</div>
matchVehicles($cus_Vehicles2)
</div>
</div>
<div class="db_record_right">
<div class="material-icons md-large md-ghost-white-enabeld w-embed">
<span class="material-icons-outlined">navigate_next</span>
</div>
</div>
</div>
<span class="customerID" style="display: none">$cus_ID2</span>
</div>
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'm trying to use a while loop inside in PHP And Ajax.
But I only get the First ID, not the 2nd, 3rd and so on.
Here is the code Of PHP:
<div class="container pt-5 my-5">
<section class="p-md-3 mx-md-5 text-center">
<h2 class="text-center mx-auto font-weight-bold mb-4 pb-2">Our Team</h2>
<div class="row">
<?php while ($t_run=mysqli_fetch_array($t_query)){?>
<div class="col-lg-3 col-md-4 col-sm-6 mb-4">
<div class="p-4">
<div class="avatar w-100 white d-flex justify-content-center align-items-center">
<input type="hidden" name="team" class='team_id' value="<?php echo $t_run['id']?>">
<img src='images/<?php echo $t_run['img']?>'class="team_img rounded-circle z-depth-1-half"/>
</div>
<div class="text-center mt-2">
<h6 class="font-weight-bold pt-2"><?php echo $t_run['name']?></h6>
<p class="text-muted">
<small><i><?php echo $t_run['title']?></i></small>
</p>
<button class="team btn-info border-0 p-2 rounded">View profile</button>
</div>
</div>
</div>
<?php }?>
</div>
</section>
and here is the Ajax code I use
<script type="text/javascript">
$(document).ready(function () {
$('.team').click(function (){
var name = $('.team_id').val();
$('#content_container').load('team-ajex.php',{
id:name
});
});
});
</script>
I'd recommend you to try to change
$('.team_id').val()
to
$(this).parent().parent().find('input[name="team"]').val()
When you try to get $('.team_id') it returns an array of all inputs with this class...
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.
it might be a stupid question but i struggle with finding the source of my problem.I have a white space from no where, pages are saved as utf-8 and my php/html adds some double quotes that generates me white space. If someone can help me with this i would be glad:)
Here is the img
The problem is between col-md-8 and cold-md-4.First function si the left content, second is the right side.
code: 1st function
function arata()
{
global $dbh;
echo'
<div class="container">
<div class="row">
<div class="col-md-8">
<div id="cale"> Acasă <img src="images/sageata.jpg"><span> Sesiuni de instruire </span> </div>
<div id="title_page"><h2>Sesiuni de instruire</h2></div>
<div id="continut">
<div class="box box-solid">
<div class="box-body">
<div class="box-group" id="accordion">
<!-- we are adding the .panel class so bootstrap.js collapse plugin detects it -->
';
$stmt = $dbh->prepare("SELECT * FROM Sesiune order by ID_Sesiune desc");
$stmt->execute();
while ($row = $stmt->fetch())
{
$id_sesiune=$row['ID_Sesiune'];
$titlu=$row['Titlu'];
$desc=$row['Descriere'];
echo' <div class="panel box box-primary">
<div class="box-header">
<h4 class="box-title">
<a data-toggle="collapse" data-parent="#accordion" href="#'.$id_sesiune.'">
'.$titlu.'
</a>
</h4>
</div>
<div id="'.$id_sesiune.'" class="panel-collapse collapse">
<div class="box-body">
'.$desc.'
</div>
</div>
</div>';
}
echo' </div>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div></div>';
}
code: 2nd function
function Stiri()
{
global $dbh;
echo'
<div class="col-md-4">
<div id="inscrie"><button type="button" class="btn2 btn-primary2" data-toggle="button">Click aici pentru înscriere<span class="glyphicon glyphicon-chevron-right"></span></button></div>
<div id="search">
<div class="input-group">
<form method="GET" class="cauta" action="cautare.php">
<input type="text" class="form-control" name="cautare" placeholder="Caută în site ...">
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</span>
</form>
</div></div>
<div id="noutati">
<h2>Noutăţi</h2>
<ul>';
$stmt = $dbh->prepare("SELECT * FROM Noutati order by Data desc limit 7");
$stmt->execute();
while ($row = $stmt->fetch())
{
echo '<li>'.$row['Titlu'].'</li>';
}
echo'</ul>
<div id="toate"><button type="button" class="btn3 btn-primary3">Toate noutăţile</button></div>
</div>
</div>
</div>
</div>';
}
───→</div>↲
───→<div class="col-md-4">...
With ↲ being a new line, and ───→ being a tab. You have space! The "quotes" you see are the DOM inspector saying "here's a text node", they're not in the source. All that's in your source, is the whitespace that you put there.
Try:
</div><div class="col-md-4">...