I have a nested comment system with replies on my site, but comments and replies gets longer and longer.
I want to Toggle/Hide replies on page load, I added id to child comments container and tried to Hide/Toggle with ajax but didn't work.
What I tried, added a button to comment parent_id ="0" and tried with toggle and hide :
$('#buttonReplies').click(function(e){
e.preventDefault();
$(this).next("#child").fadeToggle(); // $("#child").fadeToggle(); and $("#child").hide();
});
ofcourse didnt work.
My list-comments.php :
$post_id = intval($_POST["comment_post_id"]);
$parent = intval('0');
$active = 'Y';
$sth = $pdo->prepare(
"SELECT * FROM comments
JOIN profiles ON comments.com_uid = profiles.ik_uid
WHERE comments.comment_post_id = ?
AND comments.comment_parent_id = ?
AND comments.active = ? ORDER BY comment_id DESC
");
$sth->execute([$post_id, $parent, $active]);
$output = '';
while($row = $sth->fetch()){
if($row['ik_img'] !== ''){
$image = explode('.',$row['ik_img']);
$ik_img = $image[0].".webp";
$ik = $row['ik_img'];
}else{
$ik_img = 'avatar.jpg';
$ik = 'avatar.jpg';
}
$output .= '
<div class="form-group border-bottom">
<div class="row">
<div class="col-12"><b>'.htmlspecialchars(ucfirst($row["comment_sender_name"])).'</b> dedi ki!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source type="image/webp" srcset="uploads/small/'.$ik_img.'">
<img src="uploads/small/'.$ik.'" alt="'.htmlspecialchars($row['comment_sender_name']).'" class="img-fluid"></div>
</picture>
<div class="col-10 sttext">'.htmlspecialchars($row['comment']).'</div>
</div>
<div class="col-12 sttime"><i class="date">'.htmlspecialchars($row["comment_date"]).'</i>
<button type="button" class="btn btn-primary btn-xs reply" id="'.intval($row["comment_id"]).'">Reply <i class="fas fa-share"></i></button>
</div>
</div>
</div>
';
$output .= get_comments($pdo, intval($row["comment_id"]), intval($row["comment_post_id"]));
}
echo $output;
function get_comments($pdo, $parent_id = 0,$post_id, $active = 'Y', $marginleft = 0){
$stmt = $pdo->prepare(
"SELECT * FROM comments
JOIN profiles ON comments.com_uid = profiles.ik_uid
WHERE comments.comment_post_id = ?
AND comments.comment_parent_id = ?
AND comments.active = ? ORDER BY comment_id DESC
");
$stmt->execute([$post_id, $parent_id, $active]);
$count = $stmt->rowCount();
if($parent_id == 0){
$marginleft = 0;
$adclass = "";
}else{
$marginleft = $marginleft + 15;
$adclass = "child";
}
$output = '';
if($count > 0){
while($row = $stmt->fetch()){
if($row['ik_img'] !== ''){
$image = explode('.',$row['ik_img']);
$ik_img = $image[0].".webp";
$ik = $row['ik_img'];
}else{
$ik_img = 'avatar.jpg';
$ik = 'avatar.jpg';
}
$output .= '
<div id="'.$adclass.'" class="form-group border-bottom" style="padding-left:'.$marginleft.'px;">
<div class="row">
<div class="col-12"><b class="hide">'.htmlspecialchars(ucfirst($row["comment_sender_name"])).'</b> dedi ki!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source srcset="uploads/small/'.$ik_img.'" type="image/webp">
<img src="uploads/small/'.$ik.'" alt="'.htmlspecialchars($row['comment_sender_name']).'" class="img-fluid"></div>
</picture>
<div class="col-10 sttext">'.htmlspecialchars($row['comment']).'</div>
</div>
<div class="col-12 sttime"><i class="date">'.htmlspecialchars($row["comment_date"]).'</i>
<button type="button" class="btn btn-primary btn-xs reply" id="'.intval($row["comment_id"]).'">Reply <i class="fas fa-share"></i></button>
</div>
</div>
</div>
';
$output .= get_comments($pdo, intval($row["comment_id"]), $marginleft);
}
}
return $output;
}
My ajax in post-detail.php :
$(document).ready(function(){
$('#comment_form').submit(function(event){
event.preventDefault();
var form_data = $(this).serialize();
$.ajax({
url:"modules/add_comment.php",
method:"POST",
data:form_data,
dataType:"JSON",
success:function(data)
{
if(data.error != '')
{
$('#comment_form')[0].reset();
$('#comment_message').html(data.error);
$('#comment_id').val('0');
load_comment();
}
}
})
});
load_comment();
function load_comment(){
var comment_post_id =$("#comment_post_id").val();
$("#display_comment").load("modules/list_comment.php",{
comment_post_id: comment_post_id,
});
}
$(document).on('click', '.reply', function(){
var comment_id = $(this).attr("id");
$('#comment_id').val(comment_id);
$('#comment_name').focus();
});
});
Database structer :
Note: I don't use bootstrap just jquery and css.
Instead of id use class selector . Then , onclick of show replies toggle all divs(child) until next parent class using .nextUntil(".parent").slideToggle();
Demo Code :
$(".parent").nextAll("div.child").slideUp() //hide all replies div
//on click of show replies
$(document).on('click', '.show_reply', function(e) {
e.preventDefault();
//check text change it
$(this).text() == "show replies" ? $(this).text("hide replies") : $(this).text("show replies")
//get closest parent div and then slide all child till next parent
$(this).closest(".parent").nextUntil(".parent").slideToggle();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-6">
<div class="col-12">
<h3 class="mgbt-xs-20 mrgt"><img alt="Yorumlar" src="uploads/images/icons/yes.png" width="32" height="32"> Total Comments (5)
</h3>
</div>
<div class="col-12">
<div id="display_comment">
<!--added class parent-->
<div class="form-group border-bottom parent">
<div class="row">
<div class="col-12"><b>User Name</b> Said!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source type="image/webp" srcset="uploads/small/EcGzDp4bniBe.webp">
<img src="https://www.kariyer.net/ik-blog/wp-content/uploads/2016/04/hr234222.jpg" alt="User Name" class="img-fluid"></picture>
</div>
<div class="col-10 sttext">How hHow to paginate search result php pdo? How to paginate search result php pdo? How to paginate search result php pdo? How h How to paginate search result php pdo?&nbsp;How to paginate search r</div>
</div>
<div class="col-12 sttime"><i class="date">2021-01-01 06:04:20</i>
<button type="button" class="btn btn-primary btn-xs reply" id="40">Reply <i class="fas fa-share" aria-hidden="true"></i></button> <button type="button" class="btn btn-primary btn-xs show_reply" id="40">show replies</button>
</div>
</div>
</div>
<div class="form-group border-bottom child" style="padding-left:15px;">
<div class="row">
<div class="col-12"><b class="hide">User Name</b> Said!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source srcset="uploads/small/EcGzDp4bniBe.webp" type="image/webp">
<img src="https://www.kariyer.net/ik-blog/wp-content/uploads/2016/04/hr234222.jpg" alt="User Name" class="img-fluid"></picture>
</div>
<div class="col-10 sttext">This is a test comment, just to see how everything goes.</div>
</div>
<div class="col-12 sttime"><i class="date">2021-01-01 06:06:36</i>
<button type="button" class="btn btn-primary btn-xs reply" id="42">Reply <i class="fas fa-share" aria-hidden="true"></i></button>
</div>
</div>
</div>
<div class="form-group border-bottom child" style="padding-left:15px;">
<div class="row">
<div class="col-12"><b class="hide">User Name</b> Said!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source srcset="uploads/small/EcGzDp4bniBe.webp" type="image/webp">
<img src="https://www.kariyer.net/ik-blog/wp-content/uploads/2016/04/hr234222.jpg" alt="User Name" class="img-fluid"></picture>
</div>
<div class="col-10 sttext">Load more data from database using jquery Ajax php mysql</div>
</div>
<div class="col-12 sttime"><i class="date">2021-01-01 06:05:37</i>
<button type="button" class="btn btn-primary btn-xs reply" id="41">Reply <i class="fas fa-share" aria-hidden="true"></i></button>
</div>
</div>
</div>
<div class="form-group border-bottom parent">
<div class="row">
<div class="col-12"><b>User Name</b> Said!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source type="image/webp" srcset="uploads/small/EcGzDp4bniBe.webp">
<img src="https://www.kariyer.net/ik-blog/wp-content/uploads/2016/04/hr234222.jpg" alt="User Name" class="img-fluid"></picture>
</div>
<div class="col-10 sttext">How to paginate search result php pdo? How h How to paginate search result php pdo?&amp;amp;nbsp;How to paginate search result php pdo? How to paginate search result php pdo? How to paginate searc</div>
</div>
<div class="col-12 sttime"><i class="date">2021-01-01 05:59:09</i>
<button type="button" class="btn btn-primary btn-xs reply" id="38">Reply <i class="fas fa-share" aria-hidden="true"></i></button><button type="button" class="btn btn-primary btn-xs show_reply" id="38">show replies</button>
</div>
</div>
</div>
<div class="form-group border-bottom child" style="padding-left:15px;">
<div class="row">
<div class="col-12"><b class="hide">User Name</b> Said!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source srcset="uploads/small/EcGzDp4bniBe.webp" type="image/webp">
<img src="https://www.kariyer.net/ik-blog/wp-content/uploads/2016/04/hr234222.jpg" alt="User Name" class="img-fluid"></picture>
</div>
<div class="col-10 sttext">This is a test comment, just to see how everything goes.</div>
</div>
<div class="col-12 sttime"><i class="date">2021-01-01 06:06:36</i>
<button type="button" class="btn btn-primary btn-xs reply" id="42">Reply <i class="fas fa-share" aria-hidden="true"></i></button>
</div>
</div>
</div>
<div class="form-group border-bottom parent">
<div class="row">
<div class="col-12"><b>User Name</b> Said!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source type="image/webp" srcset="uploads/small/EcGzDp4bniBe.webp">
<img src="https://www.kariyer.net/ik-blog/wp-content/uploads/2016/04/hr234222.jpg" alt="User Name" class="img-fluid"></picture>
</div>
<div class="col-10 sttext">How to paginate search result php pdo?</div>
</div>
<div class="col-12 sttime"><i class="date">2021-01-01 05:58:21</i>
<button type="button" class="btn btn-primary btn-xs reply" id="37">Reply <i class="fas fa-share" aria-hidden="true"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
Related
I have a food ordering web app in PHP laravel 5.8. The items modal is working fine with the following code but when I am trying to display the deals modal in the same manner, it does not work at all. I am sharing my blade files. The "show.blade.php" file displays the entire front page where these modals have to be shown to the customer. The "modal.blade.php" file is where the modals are defined and their data is coming from the "show.blade.php" page. The first div in the modals file is the one that I want to work and the second is the one that is currently working fine. You can ignore the last modal div.
show.blade.php
#extends('layouts.front', ['class' => ''])
<?php
use Carbon\Carbon;
use App\User;
$name = new User();
?>
#section('content')
#include('restorants.partials.modals')
<section class="section pt-lg-0" id="restaurant-content" style="padding-top: 0px">
<input type="hidden" id="rid" value="{{ $restorant->id }}" />
<div class="container container-restorant">
<hr>
#if ($deals)
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<h1>Deals</h1>
#foreach ($deals as $deal)
<div class="col-xl-3 col-lg-6 col-md-6 col-sm-6">
<div class="owl-item">
<div id="addToCart1">
<div class="strip">
<figure style="border-radius: 3rem">
<a onClick="setCurrentDeal({{ $deal->id }})" href="javascript:void(0)"><img
src="{{ $deal->image_url }}_thumbnail.jpg" loading="lazy"
data-src="{{ config('global.restorant_details_image') }}"
class="img-fluid lazy" alt=""></a>
</figure>
<span class="res_title"><b><a onClick="setCurrentDeal({{ $deal->id }})"
href="javascript:void(0)">{{ $deal->name }}</a></b></span><br />
<span class="res_description">{{ $deal->description }}</span><br />
<div class="d-flex justify-content-between">
<div>
#php
$dealItems = [];
$dealItems = App\DealItem::where('deal_id', $deal->id)->get();
#endphp
#foreach ($dealItems as $it)
<h6><strong>{{ $it->item->name }}</strong></h6>
#endforeach
</div>
<h6 class="text-success"><strong>Price:{{ $deal->price }}</strong></h6>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="owl-dots">
<div class="owl-dot active"><span></span></div>
<div class="owl-dot"><span></span></div>
<div class="owl-dot"><span></span></div>
</div>
</div>
#endforeach
#endif
</div>
#section('js')
<script>
$(function() {
$('.owl-carousel').owlCarousel({
margin: 50,
autoplay: true,
loop: true
});
});
var deals = [];
var currentDeal = null;
var currentDealSelectedPrice = null;
var lastAdded = null;
var CASHIER_CURRENCY = "<?php echo env('CASHIER_CURRENCY', 'usd'); ?>";
var LOCALE = "<?php echo App::getLocale(); ?>";
/*
* Price formater
* #param {Nummber} price
*/
function formatPrice(price) {
var formatter = new Intl.NumberFormat(LOCALE, {
style: 'currency',
currency: CASHIER_CURRENCY,
});
var formated = formatter.format(price);
return formated;
}
function setCurrentDeal(id) {
var deal = deals[id];
currentDeal = deal;
$('#modalDealTitle').text(deal.name);
$('#modalDealName').text(deal.name);
$('#modalDealPrice').html(deal.price);
$('#modalDealID').text(deal.id);
$("#modalDealImg").attr("src", deal.image);
$('#modalDealDescription').html(deal.description);
//Normal
currentDealSelectedPrice = deal.priceNotFormated;
// $('#variants-area').hide();
$('.quantity-area').show();
$('#dealModal').modal('show');
}
<?php
$deals =[];
foreach ($deals as $deal){
$theArray = [
'name' => $deal->name,
'id' => $deal->id,
'priceNotFormated' => $deal->price,
'price' => #money($deal->price, env('CASHIER_CURRENCY', 'usd'), true) . '',
'image' => $deal->logom,
'description' => $deal->description,
];
echo 'deals[' . $deal->id . ']=' . json_encode($theArray) . ';';
}
?>
<script>
$(document).ready(function() {
$("#addToCart1").show();
// $('#exrtas-area').show();
$('.quantity-area').show();
});
</script>
#endsection
modals.blade.php
<div class="modal fade" id="dealModal" z-index="9999" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="modalDealTitle" class="modal-title" id="modal-title-new-item"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body p-0">
<div class="card bg-secondary shadow border-0">
<div class="card-body px-lg-5 py-lg-5">
<div class="row">
<div class="col-sm col-md col-lg col-lg text-center">
<img id="modalDealImg" src="" width="295px" height="200px">
</div>
<div class="col-sm col-md col-lg col-lg">
<input id="modalDealID" type="hidden"></input>
<span id="modalDealPrice" class="new-price"></span>
<p id="modalDealDescription"></p>
</div>
<div class="offset-md-6 col-md-6">
#if(!config('app.isqrsaas'))
<div class="quantity-area">
<div class="form-group">
<br />
<label class="form-control-label" for="quantity">{{ __('Quantity') }}</label>
<input type="number" name="quantity" id="quantity" class="form-control form-control-alternative" placeholder="{{ __('1') }}" value="1" required autofocus>
</div>
<div class="quantity-btn float-right">
<div id="addToCart1">
<button class="btn btn-primary" v-on:click='addToCartAct'
<?php
if(auth()->user()){
if(auth()->user()->hasRole('client')) {echo "";} else {echo "disabled";}
}else if(auth()->guest()) {echo "";}
?>
>{{ __('Add To Cart') }}</button>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="productModal" z-index="9999" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="modalTitle" class="modal-title" id="modal-title-new-item"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body p-0">
<div class="card bg-secondary shadow border-0">
<div class="card-body px-lg-5 py-lg-5">
<div class="row">
<div class="col-sm col-md col-lg col-lg text-center">
<img id="modalImg" src="" width="295px" height="200px">
</div>
<div class="col-sm col-md col-lg col-lg">
<input id="modalID" type="hidden"></input>
<span id="modalPrice" class="new-price"></span>
<p id="modalDescription"></p>
<div id="variants-area">
<label class="form-control-label">{{ __('Select your options') }}</label>
<div id="variants-area-inside">
</div>
</div>
</div>
<div class="col-md-12">
<div id="exrtas-area">
<br />
<label class="form-control-label h4" for="quantity">{{ __('Extras') }}</label>
<div class="row" id="exrtas-area-inside"></div>
</div>
</div>
<div class="offset-md-6 col-md-6">
#if(!config('app.isqrsaas'))
<div class="quantity-area">
<div class="form-group">
<br />
<label class="form-control-label" for="quantity">{{ __('Quantity') }}</label>
<input type="number" name="quantity" id="quantity" class="form-control form-control-alternative" placeholder="{{ __('1') }}" value="1" required autofocus>
</div>
<div class="quantity-btn float-right">
<div id="addToCart1">
<button class="btn btn-primary" v-on:click='addToCartAct'
<?php
if(auth()->user()){
if(auth()->user()->hasRole('client')) {echo "";} else {echo "disabled";}
}else if(auth()->guest()) {echo "";}
?>
>{{ __('Add To Cart') }}</button>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I've been working on my webpage but somehow bootstrap would not show it properly. Below is my code:
<div class="main-panel">
<div class="content-wrapper">
<button type="button" class="btn btn-primary btn-rounded btn-icon" data-toggle="modal" data-target="#newGroupModal">
<i class="ti-plus"></i>
</button>
<div class="row">
<form method="post">
<?php
foreach($data as $row) {
?>
<div class="col-md-4">
<div class="card-body">
<div class="card">
<img class="card-img-top" src="../../template/images/banner.png" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">
<?=$row['group_name']?>
</h5>
<p class="card-text"></p>
<a class="btn btn-primary" href="view_group.php?group_id=<?=$row['group_id']?>">View Group</a>
</div>
</div>
</div>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
I want it to be 3 column in a row but I ended up like this:
Click here to view the picture
I'm not sure whats wrong with my code, if anybody could help me identify it would be great. Thank you so much
<div class="main-panel">
<div class="content-wrapper">
<button type="button" class="btn btn-primary btn-rounded btn-icon" data-toggle="modal" data-target="#newGroupModal">
<i class="ti-plus"></i>
</button>
<div class="row">
<?php
foreach($data as $row) {
?>
<div class="col-4">
<form method="post">
<div class="card"> <div class="card-body">
<img class="card-img-top" src="../../template/images/banner.png" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">
<?=$row['group_name']?>
</h5>
<p class="card-text"></p>
<a class="btn btn-primary" href="view_group.php?group_id=<?=$row['group_id']?>">View Group</a>
</div>
</div>
</div>
</form>
</div>
<?php } ?>
</div>
</div>
</div>
Explaination:
Change position of: <form> and <form>
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 making an e-commerce capstone project. The query is already okay but the problem is with displaying the data. If I choose a different category the current category will be hidden and only the new category will be displayed.
https://imgur.com/a/YsLj9S2
<section>
<div class="container">
<div class="row justify-content-center">
<div class="col-sm-9" style="border:solid 1px;">
<div class="row">
<div class="col-sm-4" id="test3">
<div class="card" id="test">
<div class="card-body" id="test2">
<div class="product-grid">
<div class="product-image">
<a href="#" class="image" style="background-color:#F3F3F3;">
<img class="pic-1" src="https://media.comicbook.com/2020/05/dragon-ball-super-when-will-should-goku-master-ultra-instinct-1219439.jpeg?auto=webp&width=1200&height=628&crop=1200:628,smart" class="d-block w-100" id>
</a>
<a class="add-to-cart" id="cart" href=""> + </a>
</div>
<div class="product-content">
<h3 class="title" id="productname">Product Name</h3>
<div class="price" id="price"></div>
</div>
<div class="action-buttons">
<button class="btn btn-danger mt-3" id="cart" onclick="addtocart()"><i class="fas fa-shopping-cart"></i> Add to Cart</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
function searchcategory(category_id) {
$.ajax({
url: "<?php echo base_url() ?>admin/getproducts/" + category_id,
type: "POST",
dataType: "json",
success: function(data) {
$.each(data, function(key, value) {
let row = `<div class="price" id="price">${value.price}</div>`;
let val = `<h3 class="title" id="productname">${value.product_name}</h3> `;
let test = `<button class="btn btn-danger mt-3" id="cart" onclick="${value.product_id}" ><i class="fas fa-shopping-cart"></i> Add to Cart</button>`;
$('#price').append(row);
$('#price').append();
$('#productname').append(val);
/* $('#test3').append(val);
$('#cart').text(test); */
console.log(test);
});
}
});
}
I have a problem updating a section of a laravel view. that section is in another view and is filled with the data of a db. What I want to do is that when clicking on a link that content is filtered and the other parts of the page remain as they were.
thanks
coursesCategories.blade.php
#extends('courses')
#section('content')
#extends('courses')
#section('content')
<div class="tab-pane fade show active" id="pills-todas" role="tabpanel" aria-labelledby="pills-todas-tab">
<div class="row justify-content-sm-center">
#foreach($cursos as $curso)
<div class="col col-12 col-sm-12 col-md-6 col-lg-4 vista_curso">
<div class="card column_course">
<a><img class="card-img-top img_course" src="{{ asset('assets/images/pictureDefault.png') }}" alt="Foto de curso" width="240" height="135"></a>
<div class="card-body column_course_interna">
<div class="include">
<div class="card-title titulo_curso">
<h3><b>{{ $curso->nombre }}</b></h3>
</div>
<ul>
<li>
<i class="fas fa-file col-1"></i>
<span class="lista_contenido col-11"> 4 documentos explicativos </span>
</li>
<li>
<i class="fas fa-clock col-1"></i>
<span class="lista_contenido col-11"> 32 minutos </span>
</li>
</ul>
</div>
<div class="compra">
<div><button type="button" class="btn btn-lg btn_suscribe btn_ver" style="width: 84%;">Ver Curso</button></div>
<div><button type="button" class="btn btn-lg btn_suscribe" style="width: 84%;">Suscribirse</button></div>
</div>
<div class="texto_precio">
<span class="price">20.99€</span>
</div>
</div>
</div>
</div>
#endforeach
</div>
</div>
#stop#stop
courses.blade.php
<div id="mostrar_cursos" class="container-fluid justify-content-center mostrar_cursos">
<div class="btn_filtros"> <button id="btn_filtros" type="button" class="btn btn-primary btn-sm btn-block d-md-none" onclick="viewfilter();ocult()">Filtrar</button></div>
<div class="row">
<div class="d-none d-md-block col col-md-4 col-lg-3 filter" style="max-width: 304px">
<div class="nav flex-column nav-pills" id="pills-tab" role="tablist" aria-orientation="vertical">
<a class="nav-link active" id="pills-todas-tab" href="{{ action('CoursesController#showList') }}" role="tab" aria-controls="pills-todas" aria-selected="true">Todas</a>
#foreach($categorias as $categoria)
<a class="nav-link" id="pills-ofimatica-tab" href="{{ action('CoursesController#showCourses', $categoria->nombre) }}" role="tab" aria-controls="pills-".$categoria aria-selected="false">{{ $categoria->nombre }}</a>
#endforeach
</div>
<div class="rango_precio">
<form>
<label for="customRange">Rango de precio</label>
<input type="range" class="custom-range" id="customRange">
</form>
<div id="result">Valor menor que:
<b id="valor"></b>
<strong>€</strong>
</div>
</div>
<div class="order_by">
<button id="btn_ordenar" class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Ordenar por precio
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2">
<button class="dropdown-item" type="button">Precio más alto</button>
<button class="dropdown-item" type="button">Precio más bajo</button>
</div>
</div>
</div>
<div class="col col-md-8 col-lg-9 row">
<div class="navegador_category container">
<div class="tab-content" id="pills-tabContent">
#yield('content')
</div>
</div>
</div>
</div>
</div>
coursesController
class CoursesController extends Controller
{
// list all categories and courses
public function showList() {
// categories extracted from the bd
$categorias = \App\Categoria::listaTodasLasCategorias();
// filtering courses according to html
$cursos = \App\Curso::listaTodosLosCursos();
return view('courses.coursesCategories',['cursos' => $cursos, 'categorias' => $categorias]);
}
// list all categories and courses
public function showCourses(Request $request, String $category) {
// categories extracted from the bd
$categorias = \App\Categoria::listaTodasLasCategorias();
// filtering courses according to html
$cursos = \App\Curso::listarCursosPorCategoria($category);
$view = View::make('courses.coursesCategories', ['cursos' => $cursos]);
if(Request::ajax()) {
$sections = $view->renderSections(); // returns an associative array of 'content', 'head' and 'footer'
return $sections['content']; // this will only return whats in the content section
}
return $view;
}
}
routes
Route::get('/courses', 'CoursesController#showList');
Route::get('/courses/{category}', 'CoursesController#showCourses');