Carousel with three items on each slide - php

I just can't get my head around this.
I want to fetch product images/items from the database and show in a carousel. But i want to have 3 images/items on each slide.
I have tested that it work by just hardcoding/repeating the code, but i want it to work in the foreach loop that i run from the result of the database question. But i just cant get it to work properly.
Here is my code that i am working on.
<div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner"> <?php
$x=0;
foreach($result as $r)
{
if (($x % 3) == 0)
{?>
<div class="carousel-item <?php if($x == 0){ echo "active"; }?>">
<div class="album py-5 bg-light">
<div class="container">
<div class="row"><?php
}?>
<div class="col-md-4">
<div class="card mb-4 box-shadow">
<img class="card-img-top" style="max-height: 300px"
src="../productimages/<?php echo $r['pid']."/".$r['filename']; ?>"
alt="Card image cap">
<div class="card-body">
<p class="card-text">This is a wider card with supporting text
below as a natural lead-in to additional content. This content
is a little bit longer.</p>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
</div>
<small class="text-muted">9 mins</small>
</div>
</div>
</div>
</div><?php
if (($x % 3) == 0)
{?>
</div>
</div>
</div>
</div><?php
}
$x++;
}?>
</div>
<button class="carousel-control-prev"
style="width: 3.5%; height: 200px; top: 30%;" type="button"
data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"><i
class="bi bi-arrow-left-square-fill text-warning" fill="black"
style="font-size: 50px; position: relative; top: -23px;"></i></span> <span
class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next"
style="width: 3.5%; height: 200px; top: 30%;" type="button"
data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
<span class="carousel-control-next-icon bs-orange" aria-hidden="true"><i
class="bi bi-arrow-right-square-fill text-warning"
style="font-size: 50px; position: relative; top: -23px;"></i></span> <span
class="visually-hidden">Next</span>
</button>
</div>

Related

my amazon cart ATC not response to my css

This is my coding line. the
<?php include '../includes/amazon-cart.php' ?>
is not responsive.
<section class="bg-secondary py-4">
<div class="container">
<div class="row no-gutters">
<div class="col-lg-5">
<img src="https://cdn.truegcloud.com/cholibrium/oto1/cholibrium-up3ds-3-bottles.png" alt="" class="img-fluid d-block mx-auto pb-4 pb-md-0" type="image">
</div>
<div class="col-lg-7">
<h2 class="text-blue text-center">
<b>New Customers Only
<br class="d-none d-md-block">- Price Per Bottle:
<span style="opacity:25%; font-weight: 600;">
<br class="d-none d-lg-block">
<s>$99</s>
</span> $27
</b>
</h2>
<h3 class="text-success text-center" style="font-size:35px;">
<b><u>Savings: $216</u></b>
</h3>
<?php include '../includes/amazon-cart.php' ?>
<form id="buy-form" action="/go/order.php" method="get">
<input type="hidden" name="pid" value="<?php echo ${$funnel.'_SKU'}; ?>">
<button type="submit"
name="submit-test"
value="1"
class="submit-order-btn btn-lg btn-yellow1 p-4 p-relative"
alt="Submit Form"
>
<h3 class="submit-texts m-0"><b>ADD TO ORDER</b></h3>
<div class="loader-wrap">
<span class="loader" style="top: 20%; left: 40%;"></span>
</div>
</button>
<?php if(!isset($_COOKIE['pp_preference']) && isset($_COOKIE['vault'])){ ?>
<p class="text-pink text-center" style="margin-top: 15px !important;text-transform: none;font-weight: 300;font-size: 15px !important;">By clicking "Add To Order" button, your card will automatically be charged.</p>
<?php } ?>
</form>
<div class="row align-items-center justify-content-around">
<div class="col-6">
<img src="https://cdn.truegcloud.com/epishieldplus/up1dssl-4b.png" alt="" class="img-fluid align-self-center d-block mx-auto" type="image">
</div>
<div class="col-6">
<img src="https://cdn.truegcloud.com/epishieldplus/up1dssl-2b.png" alt="" class="img-fluid align-self-center d-block mx-auto" type="image">
</div>
</div>
</div>
</div>
</div>
</section>
but now it became like this
It supposed to be like this

Printing HTML dom inside PHP foreach loop

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

How to get button information and pass to another PHP page?

I want to get the information from this formwhen you press the add to cart button. and i want to use that information in a cart page.
<?php
$result = mysqli_query($conn,$query);
$output = '';
while($row = mysqli_fetch_assoc($result)) {
$output .= '
<div style="margin-bottom: 20px;" class="col-lg-3 col-md-6 col-sm-6">
<form method="post ">
<div style="height: 400px;" class="card shadow text-center">
<div class="card-block shop-item">
<img class="shop-item-image" src="Bilder/clothes/'. $row['ProductImage'].'" alt="" class="img-fluid" style="height: 200px;">
<div class="card-text shop-item-title">
'.$row['Brand'].'
</div>
<div class="card-text">
'.$row['Quantity'].' in stock
</div>
<div class="shop-item-details">
<div class="card-text" shop-item-price>
<h3>£ '.$row['Price'].'</h3>
</div>
<input style="width: 80%; margin-left: 10%; " type="text" name="quantity" class="form-control" value="1"/>
<button style="margin-top: 10px; margin-bottom: 10px; background-color:#FB8122; border: none; color:black;"href="#" class="shop-item-button btn btn-primary ">Add to cart <span class="fas fa-cart-arrow-down"></span></button>
</div>
</div>
</div>
</form>
</div>;';
}
echo $output;
}
?>
First time asking so sorry if I did something wrong

How to hide image in PHP if there is no image set

How do I hide the image tag if there is no image present? Basically, I have an image gallery that has 4 images that can be set. However, if a product has 2 images how do I hide the other 2 image tags? What would be the best method to use?
<img src="/images/large/<?=$prod_id?>.jpg" onclick="openModal();currentSlide(1)" style="border: 1px solid #cccccc;" class="hover-single"/>
<div class="row">
<p style="text-align:center;">Click on image to enlarge</p>
<div class="column">
<img src="/images/large2/<?=$prod_id?>.jpg" style="width:80px; height:80px; border-right: 1px solid #cccccc; padding-right: 5px;" onclick="openModal();currentSlide(2)" class="hover-shadow cursor">
</div>
<div class="column">
<img src="/images/large3/<?=$prod_id?>.jpg" style="width:80px; height:80px; border-right: 1px solid #cccccc; padding-right: 5px;" onclick="openModal();currentSlide(3)" class="hover-shadow cursor">
</div>
<div class="column">
<img src="/images/large4/<?=$prod_id?>.jpg" style="width:80px; height:80px;" onclick="openModal();currentSlide(4)" class="hover-shadow cursor">
</div>
</div>
<div id="myModal" class="modal" style="display: block;">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="modal-content">
<div class="mySlides" style="display: block;">
<div class="numbertext">1 / 4</div>
<img src="/images/large1/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">2 / 4</div>
<img src="/images/large2/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">3 / 4</div>
<img src="/images/large3/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">4 / 4</div>
<img src="/images/large4/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<a class="prev" onclick="plusSlides(-1)"><</a>
<a class="next" onclick="plusSlides(1)">></a>
<div class="caption-container">
<p id="caption"></p>
</div>
<div class="column">
<img class="gallery cursor active" src="/images/large1/<?=$prod_id?>.jpg" style="width:95%; height:95%;" onclick="currentSlide(1)">
</div>
<div class="column">
<img class="gallery cursor" src="/images/large2/<?=$prod_id?>.jpg" style="width:95%; height:95%;" onclick="currentSlide(2)">
</div>
<div class="column">
<img class="gallery cursor" src="/images/large3/<?=$prod_id?>.jpg" style="width:95%; height:95%;" onclick="currentSlide(3)">
</div>
<div class="column">
<img class="gallery cursor" src="/images/large4/<?=$prod_id?>.jpg" style="width:95%; height:95%;" onclick="currentSlide(4)">
</div>
</div>
</div>
Your modal-content code can be rewritten as below:
check if the image file exists or not
display the slide if the image file exists, do nothing if not.
for($i = 1; $i<=4; $i++) {
$img_file = '/images/large'.$i.'/'.$prod_id.'.jpg';
if(file_exists($img_file)) {
$display = ($i == 1) ? ' block' : ' none';
echo '<div class="mySlides" style="display:'.$display.';">';
echo ' <div class="numbertext">'.$i.' / 4</div>';
echo ' <img src="'.$img_file.'" style="width:95%; height:95%; margin-left: 2.5%;">';
echo '</div>';
}
}
The above code can be used to replace the following code section:
<div class="mySlides" style="display: block;">
<div class="numbertext">1 / 4</div>
<img src="/images/large1/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">2 / 4</div>
<img src="/images/large2/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">3 / 4</div>
<img src="/images/large3/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">4 / 4</div>
<img src="/images/large4/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
Sure it is not the best way to check file_exists each time. This can be improved by means of storing the number of images for each product in your data set / database. Then just set a new variable such as $img_num to replace the 4 in the loop.
Try this code:
<div class="row">
<p style="text-align:center;">Click on image to enlarge</p>
<div class="column">
<?php if(file_exists('/images/large2/'.$prod_id.'.jpg')){<?php>
<img src="/images/large2/<?=$prod_id?>.jpg" style="width:80px; height:80px; border-right: 1px solid #cccccc; padding-right: 5px;" onclick="openModal();currentSlide(2)" class="hover-shadow cursor"><?php }
</php>
Here is possible idea for your requirement :
$query = "here is your query";
$res = "your query executed";
$imagearray = array();
$i = 0;
while($row = mysql_fetch_array($res))
{
if(file_exists(imagepath.$row["image"]))
{
$imagearray[$i] = $row["image"];
$i++
}
}
Hi their Brother ild flue did a good work, but we can enhance the code a bit more but making the fetching a bit more dynamic, I propose the code below,
scan the dir for existing folders(in that way u don't need to depend
on the arbitrary number to indicate the folder
see that those paths with ur image exist or not
display the specified images and let the rest of the be discarded.
<div id="myModal" class="modal" style="display: block;">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="modal-content">
<?php
$k=1;
$dirs = array_filter(glob('images/*'), 'is_dir');
foreach ( $dirs as $allLargeDir ){
$imgPath=$allLargeDir."/".$prod_id.".jpg";
if(file_exists($imgPath)){
?>
<div class="mySlides" style="display: block;">
<div class="numbertext"><?php echo $k++." / ".$n; ?></div>
<img src="<?php echo $imgPath;?>" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<?php
}
}
?>

How to append the value in forloop and jquery HTML

I want to do PG booking, I have one form field in that field(index.php) i select room sharing like 1 sharing or 2 sharing etc...after select this pg sharing i passed the value in next page(pg_deatils.php) through AJAX and i select from DB which room are having 1 sharing or 2 sharing after i return the value in index.php still i am getting correct after that i want append the value in html,insteed of Room 1,Romm 2... i want append the value of console.log(value.pg_id);// 2,1 and insteed of Bed 1,Bed1...i want to append console.log(value.room_number);//room1,room2
function showDiv(toggle){
var sharing=$("#sharing").val();
$.ajax({
type: "POST",
url: "pg_details.php",
data: "sharing_id="+sharing,
success: function(data) {
var res =jQuery.parseJSON(data);
console.log(res);
if(res['return'] == 1){
var htmlString='';
$.each( res['data'], function( key, value ){
console.log(value.pg_id);// 2,1
console.log(value.room_number);//room1,room2
});
}
}
});
}
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<h3 style="text-align:center;color:white; margin-top:70px;padding-bottom:30px;">PG Booking System</h3>
<form class="form-horizontal" >
<div class="form-group">
<label class="control-label col-sm-2" for="phone">Sharing:</label>
<div class="col-sm-10">
<select class="form-control" name="sharing" id="sharing">
<option value="">---select---</option>
</select>
</div>
</div>
<div class="form-group" style="margin-top:30px;">
<div class="col-sm-offset-5 col-sm-8">
<button type="button" class="btn btn-primary" name="answer" onclick="showDiv('toggle')" style=" margin-top:50px;margin-bottom:50px;">Submit</button>
</div>
</div>
</form>
</div>
<div class="col-md-3"></div>
</div>
<!--This HTML i want to append-->
<div id="toggle" style="display:none">
<div class="container" style=" margin-bottom: 30px;">
<div class="row">
<h4 style="margin-left:15px;">PG NAME 1</h4>
<div class="col-sm-10">
<div class="btn-group" id="btnmar">
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed 1</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 2</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed 3</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed 4</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 5</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed 6</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 7</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 8</button>
</a>
</div>
</div>
<!--hidden 6 end-->
<!--hidden 4 start-->
<div class="col-sm-2">
<div class="panel-group">
<div class="panel panel-primary">
<div class="panel-heading"> Premium Facility</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-television" aria-hidden="true" style="margin-right:15px;"></i>T.V.</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-wifi" aria-hidden="true" style="margin-right:15px;"></i>Wifi</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-bed" aria-hidden="true" style="margin-right:15px;"></i>Bed</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-shopping-basket" aria-hidden="true" style="margin-right:15px;"></i>Washing Machine</div>
</div>
</div>
</div>
<!--hidden 4 end-->
</div>
<!--row1 end-->
<!--row2 start-->
<div class="row">
<h4 style="margin-left:15px;">PG NAME 2</h4>
<div class="col-sm-10">
<div class="btn-group" id="btnmar">
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 1</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 2</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 3</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 4</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 5</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 6</button>
</a>
</div>
</div>
<!--hidden 6 end-->
<!--hidden 4 start-->
<div class="col-sm-2">
<div class="panel-group">
<div class="panel panel-primary">
<div class="panel-heading"> Classic Facility</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-television" aria-hidden="true" style="margin-right:15px;"></i>T.V.</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-wifi" aria-hidden="true" style="margin-right:15px;"></i>Wifi</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-bed" aria-hidden="true" style="margin-right:15px;"></i>Bed</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-shopping-basket" aria-hidden="true" style="margin-right:15px;"></i>Washing Machine</div>
</div>
</div>
</div>
<!--hidden 4 end-->
</div>
<!--row2 end-->
<!--row2 start-->
<div class="row">
<h4 style="margin-left:15px;">PG NAME 3</h4>
<div class="col-sm-10">
<div class="btn-group" id="btnmar">
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 1</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 2</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 3</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 4</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 5</button>
</a>
</div>
</div>
<!--hidden 6 end-->
<!--hidden 4 start-->
<div class="col-sm-2">
<div class="panel-group">
<div class="panel panel-primary">
<div class="panel-heading"> Basic Facility</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-television" aria-hidden="true" style="margin-right:15px;"></i>T.V.</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-wifi" aria-hidden="true" style="margin-right:15px;"></i>Wifi</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-bed" aria-hidden="true" style="margin-right:15px;"></i>Bed</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-shopping-basket" aria-hidden="true" style="margin-right:15px;"></i>Washing Machine</div>
</div>
</div>
</div>
<!--hidden 4 end-->
</div>
<!--row3 end-->
</div>
</div>
pg_details.php
<?php
include_once("admin/config.php");
include("functions.php");
//$pg_name=Getpg($_POST['pg_id']);
$sharing=$_POST['sharing_id'];//Getting Sharing Value
$sql=mysql_query("SELECT * FROM rooms WHERE room_sharing='$sharing'");
$count = mysql_num_rows($sql);
if($count > 0){
while($row=mysql_fetch_assoc($sql)){
$data[]= $row;
}
$pg_type= array("return"=>1,"count" =>$count,"data" =>$data);
echo $pg_type = json_encode($pg_type);
}else{
$pg_type= array("return"=>0,"count" =>0,"data" =>"");
echo $pg_type = json_encode($pg_type);
}
?>
I assumed certain data from your database table and created this. You will have to tweak it all a little to get it according to your data.
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<h3 style="text-align:center;color:white; margin-top:70px;padding-bottom:30px;">PG Booking System</h3>
<form class="form-horizontal" >
<div class="form-group">
<label class="control-label col-sm-2" for="phone">Sharing:</label>
<div class="col-sm-10">
<select class="form-control" name="sharing" id="sharing">
<option value="">---select---</option>
<!-- <?php
$sql = "SELECT * FROM sharing";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo '<option value="'.$row["id"].'">'.$row["sharing_type"].'</option>';
}
?>-->
<option value='1'>one</option>
<option value='2'>two</option>
<option value='3'>three</option>
</select>
</div>
</div>
<div class="form-group" style="margin-top:30px;">
<div class="col-sm-offset-5 col-sm-8">
<button type="button" class="btn btn-primary" name="answer" onclick="showDiv('toggle')" style=" margin-top:50px;margin-bottom:50px;">Submit</button>
</div>
</div>
</form>
</div>
<div class="col-md-3"></div>
</div>
//////This HTML i want to append
<div id="toggle" style="display:none">
<div class="container" id='pgDetails' style=" margin-bottom: 30px;">
</div>
</div>
<script>
function showDiv(toggle){
var sharing=$("#sharing").val();
$.ajax({
type: "POST",
url: "pg_details.php",
data: "sharing_id="+sharing,
success: function(data) {
var res =jQuery.parseJSON(data);
console.log(res);
if(res['return'] == 1){
$( "#toggle" ).show();
var htmlString='';
$.each( res['data'], function( key, value ){
console.log(value.pg_id);// 2,1
console.log(value.room_number);//room1,room2
var htmlString = '<div class="row">\n\
<h4 style="margin-left:15px;">' + value.pg_name +'</h4>\n';
htmlString += '<div class="col-sm-10"> <div class="btn-group" id="btnmar">\n ';
for(var i=1; i<value.beds+1; i++) {
htmlString += '<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed ' + i + '</button>\n';
}
htmlString += '</div>\n</div>\n';
htmlString += '<div class="col-sm-2">\n\
<div class="panel-group">\n\
<div class="panel panel-primary">\n\
<div class="panel-heading"> Premium Facility</div>\n';
var facArr = value.facility.split(',');
for(var i=0; i<facArr.length; i++) {
htmlString += '<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-television" aria-hidden="true" style="margin-right:15px;"></i>' + facArr[i] +'</div>';
}
htmlString += '</div> </div> </div> </div>';
$('#pgDetails').append(htmlString);
});
}
else {
$( "#toggle" ).hide();
}
}
});
}
</script>
pg_details.php
<?php
//include_once("admin/config.php");
//include("functions.php");
////$pg_name=Getpg($_POST['pg_id']);
//$sharing=$_POST['sharing_id'];//Getting Sharing Value
//
//$sql=mysql_query("SELECT * FROM rooms WHERE room_sharing='$sharing'");
//$count = mysql_num_rows($sql);
//if($count > 0){
// while($row=mysql_fetch_assoc($sql)){
// $data[]= $row;
// }
// $pg_type= array("return"=>1,"count" =>$count,"data" =>$data);
// echo $pg_type = json_encode($pg_type);
//}else{
// $pg_type= array("return"=>0,"count" =>0,"data" =>"");
// echo $pg_type = json_encode($pg_type);
//}
//
$row["pg_id"] = 1;
$row["room_number"] = 102;
$row["pg_name"] = "PG Name 1";
$row["beds"] = 4;
$row["facility"] = "T.V, WiFi, Bed, Washing Machine";
$data[] = $row;
$row["pg_id"] = 1;
$row["room_number"] = 502;
$row["pg_name"] = "PG Name 2";
$row["beds"] = 7;
$row["facility"] = "T.V, WiFi, Bed";
$data[] = $row;
$pg_type= array("return"=>1,"count" =>1,"data" =>$data);
echo $pg_type = json_encode($pg_type);
?>

Categories