I have two table with names courses and episodes in my Database
I want to send a course and episode in database
course_id is foreign key in episode table
i create form with 2 episode and when i'm trying to send it did not work and just send a course not episode
here my controller method :
public function SendToDB(Request $request)
{
$new_Course = new Course($this->Validatepost());
$new_Course->user_id = 1;
$new_Course->image = 'Pics/' . $this->UploadPic(request());
$new_Course->save();
$new_Course->tag()->attach(request('tag'));
$courseID = $new_Course->id;
$episode_number = request()->input('episodes_number');
for ($x = 0; $x < $episode_number; $x++) {
$new_Episode = new Episode($this->validateepisode($episode_number));
$new_Episode->course_id = $courseID;
$new_Episode->save();
return redirect('/Admin/');
}
}
and validate methods
private function Validatepost()
{
return request()->validate([
'title' => 'required',
'body' => 'required',
'price' => 'required'
]);
}
private function validateepisode($id)
{
return request()->validate([
'Episode_Title_' . $id => 'required',
'Episode_Body_' . $id => 'required',
]);
}
and my front
#extends('Admin.layout')
#section('header')
<script src="{{ asset('js/app.js') }}"></script>
<script type="text/javascript" src="/tinymce/tinymce.min.js"></script>
<script>
tinymce.init({
selector: '#mytextarea',
skin: 'oxide-dark',
content_css: 'dark'
});
function next() {
document.getElementById("base-tab-2").className = "nav-link";
document.getElementById('ProgressBar').style.width = "50%"
$('#base-tab-2').trigger('click')
}
function prev() {
document.getElementById('ProgressBar').style.width = "25%"
$('#base-tab-1').trigger('click')
}
function finish() {
document.getElementById("base-tab-3").className = "nav-link";
document.getElementById('ProgressBar').style.width = "75%";
var courseName = document.getElementById('title').value;
var courseprice = document.getElementById('price').value;
var episodeNumer = document.getElementById('episodes_number').value;
document.getElementById('courseName').innerText = courseName;
document.getElementById('coursePrice').innerText = courseprice;
document.getElementById('courseNumber').innerText = episodeNumer;
$('#base-tab-3').trigger('click')
}
function addepisode(number) {
for (var i = 0; i < number; i++) {
//////////////////////////////////////////
var element = document.createElement("input");
var label = document.createElement("Label");
label.innerHTML = "تیتر";
element.setAttribute("type", "text");
element.setAttribute("name", "Episode_Title_" + i);
element.setAttribute("class", "form-control");
label.setAttribute("class", "col-lg-3 form-control-label ");
var div = document.getElementById("test");
div.appendChild(label);
div.appendChild(element);
/////////////////////////////////
var body = document.createElement("textarea");
var bodylabel = document.createElement("Label");
bodylabel.innerHTML = "بدنه";
body.setAttribute("id", "mytextarea");
body.setAttribute("name", "Episode_Body_" + i);
body.setAttribute("class", "form-control");
bodylabel.setAttribute("class", "col-lg-3 form-control-label ");
var div = document.getElementById("test");
div.appendChild(bodylabel);
div.appendChild(body);
}
next();
}
</script>
#endsection
#section('content')
<div class="container-fluid">
<!-- Begin Page Header-->
<div class="row">
<div class="page-header">
<div class="d-flex align-items-center">
<h2 class="page-header-title">افزودن</h2>
</div>
</div>
</div>
<!-- End Page Header -->
<div class="col-xl-12">
<!-- Basic Tabs -->
<div class="widget has-shadow">
<div class="widget-header bordered no-actions d-flex align-items-center">
<h4>افزودن</h4>
</div>
<div class="widget-body sliding-tabs">
<div class="progress progress-lg mb-3">
<div class="progress-bar bg-info" id="ProgressBar" role="progressbar" style="width: 25%"
aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">روند پیشرفت
</div>
</div>
<ul class="nav nav-tabs" id="example-one" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="base-tab-1" data-toggle="tab" href="#tab-1"
onclick="document.getElementById('ProgressBar').style.width = '25%'" role="tab"
aria-controls="tab-1" aria-selected="true">مشخصات دوره</a>
</li>
<li class="nav-item ">
<a class="nav-link disabled" id="base-tab-2" data-toggle="tab" href="#tab-2"
onclick="document.getElementById('ProgressBar').style.width = '50%'" role="tab"
aria-controls="tab-2" aria-selected="false">مشخصات قسمت ها</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" id="base-tab-3" data-toggle="tab" href="#tab-3"
onclick="document.getElementById('ProgressBar').style.width = '75%'" role="tab"
aria-controls="tab-3" aria-selected="false">بازبینی</a>
</li>
</ul>
<form class="form-horizontal" method="post" action="/Admin/Createnew" enctype="multipart/form-data">
#csrf
<div class="tab-content pt-3">
<div class="tab-pane fade show active" id="tab-1" role="tabpanel"
aria-labelledby="base-tab-1">
<div class="widget-body">
<div class="form-group row d-flex align-items-center mb-5 ">
<label
class="col-lg-3 form-control-label #error('title') text-danger #enderror">تیتر</label>
<div class="col-lg-9">
<input type="text" id="title" name="title" value="{{old('title')}}"
class="form-control #error('title') border border-danger #enderror">
</div>
</div>
<div class="form-group row d-flex align-items-center mb-5 ">
<label
class="col-lg-3 form-control-label #error('price') text-danger #enderror">قیمت</label>
<div class="col-lg-9">
<input type="number" id="price" name="price" value="{{old('price')}}"
class="form-control #error('price') border border-danger #enderror">
</div>
</div>
<div class="form-group row d-flex align-items-center mb-5 ">
<label
class="col-lg-3 form-control-label #error('episodes_number') text-danger #enderror">تعداد
قسمت ها</label>
<div class="col-lg-9">
<input type="number" id="episodes_number" name="episodes_number"
value="{{old('episodes_number')}}"
class="form-control #error('episodes_number') border border-danger #enderror">
</div>
</div>
<div class="form-group row d-flex align-items-center mb-5 ">
<label
class="col-lg-3 form-control-label #error('body') text-danger #enderror">بدنه</label>
<div class="col-lg-9">
<textarea class="form-control #error('body') border border-danger #enderror"
name="body" id="mytextarea" rows="15">
{{old('body')}}
</textarea>
</div>
</div>
<div class="form-group row mb-5">
<label class="col-lg-3 form-control-label #error('tag') text-danger #enderror">تگ
ها</label>
<div class="col-lg-9 select mb-3">
<select name="tag[]"
class="custom-select form-control #error('tag') border border-danger #enderror"
multiple>
<option value="یک تگ را انتخاب کنید">یک تگ را انتخاب کنید</option>
#foreach($tags as $tag)
<option value="{{$tag->id}}">{{$tag->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="exampleFormControlFile1">عکس</label>
<input type="file" class="form-control-file" name="Pic"
id="exampleFormControlFile1">
</div>
<div class="form-group">
<button type="button"
onclick="addepisode(document.getElementById('episodes_number').value)"
class="btn btn-gradient-03 mr-1 mb-2">بعدی
</button>
</div>
</div>
</div>
<div class="tab-pane fade" id="tab-2" role="tabpanel" aria-labelledby="base-tab-2">
<div class="form-group row d-flex align-items-center mb-5 " id="test"></div>
<div class="form-group">
<button type="button" onclick="prev()" class="btn btn-gradient-03 mr-1 mb-2">قبلی
</button>
</div>
<div class="form-group">
<button type="button" onclick="finish()" class="btn btn-gradient-03 mr-1 mb-2">بعدی
</button>
</div>
</div>
<div class="tab-pane fade" id="tab-3" role="tabpanel" aria-labelledby="base-tab-3">
<div class="widget has-shadow">
<div id="IconRightCollapseOne" class="card-body collapse show"
data-parent="#accordion-icon-right" style="">
<div class="form-group row mb-5">
<div class="col-sm-3 form-control-label d-flex align-items-center">نام
دوره
</div>
<div id="courseName" class="col-sm-8 form-control-plaintext"></div>
</div>
<div class="form-group row mb-5">
<div class="col-sm-3 form-control-label d-flex align-items-center">قیمت
</div>
<div id="coursePrice" class="col-sm-8 form-control-plaintext"></div>
</div>
<div class="form-group row mb-5">
<div class="col-sm-3 form-control-label d-flex align-items-center">تعداد
قسمت ها
</div>
<div id="courseNumber" class="col-sm-8 form-control-plaintext"></div>
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-gradient-03 mr-1 mb-2">ارسال</button>
</div>
</div>
</div>
</form>
</div>
</div>
<!-- End Basic Tabs -->
</div>
</div>
#endsection
public function SendToDB(Request $request)
{
$new_Course = new Course($this->Validatepost());
$new_Course->user_id = 1;
$new_Course->image = 'Pics/' . $this->UploadPic(request());
$new_Course->save();
$new_Course->tag()->attach(request('tag'));
$courseID = $new_Course->id;
$episode_number = request()->input('episodes_number');
for ($x = 0; $x < $episode_number; $x++) {
$new_Episode = new Episode($this->validateepisode($episode_number));
$new_Episode->course_id = $courseID;
$new_Episode->save();
}
return redirect('/Admin/');
}
return redirect('/Admin/'); command must be end of function. Not end of "for loop"
i found my awnser
$new_Course = new Course($this->Validatepost());
$new_Course->user_id = 1;
$new_Course->image = 'Pics/' . $this->UploadPic(request());
$new_Course->save();
$new_Course->tag()->attach(request('tag'));
$courseID = $new_Course->id;
$episode_number = request()->input('episodes_number');
for ($x = 0; $x < $episode_number; $x++) {
$new_Episode = new Episode();
$new_Episode->title = \request()->input('Episode_Title_'.$x);
$new_Episode->body = \request()->input('Episode_Body_'.$x);
$new_Episode->number = $episode_number;
$new_Episode->course_id = $courseID;
$new_Episode->save();
}
return redirect('/Admin/');
}
validation function return true or false
and i must fill this data with code
i found my awnser
here my new code
public function SendToDB(Request $request)
{
$new_Course = new Course($this->ValidateCourse());
$new_Course->user_id = 1;
$new_Course->image = 'Pics/' . $this->UploadPic(request());
$new_Course->save();
$new_Course->tag()->attach(request('tag'));
$courseID = $new_Course->id;
$episode_number = request()->input('episodes_number');
for ($x = 0; $x < $episode_number; $x++) {
$new_Episode = new Episode();
$new_Episode->title = \request()->input('Episode_Title_'.$x);
$new_Episode->body = \request()->input('Episode_Body_'.$x);
$new_Episode->number = $x+1;
$new_Episode->course_id = $courseID;
$new_Episode->save();
}
return redirect('/Admin/');
}
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>
When I query from a page, I submit the form with jquery in sorgu.php. but how do i do it without making it infinite loop?
is there any other way ?
page link
header.php code search mod
<div class="modal fade" id="srcModal" tabindex="-1" role="dialog" aria-labelledby="contacthModal">
<div class="row searchArea modal-dialog modal-content" role="document">
<div class="container ">
<div class="row searchCloserow">
<div class="closeBtn" data-dismiss="modal"> <i class="fas fa-times" aria-hidden="true"></i> Kapat </div>
</div>
<div class="row searchForm d-flex justify-content-center">
<div class="col-md-2 searchText">
<span id="myModalLabel">Sipariş Sorgulama Ekranı</span>
<p>Sorgulamak istediğiniz siparişin kodunu giriniz!</p>
</div>
<div class="col-md-4 searchwell">
<input type="text" name="siparis_key" id="siparis_key" placeholder="Lütfen Sipariş Kodunu Giriniz">
</div>
<div class="col-md-2">
<a href="sorgu" id="siparis_Sorgula" type="submit" class="searchbtn anibut">
Sipariş Sorgula <i class="fas fa-question" aria-hidden="true"></i>
</a>
</div>
</div>
</div>
</div>
and header.php jquery code. here i am changing the href href="sorgu?key=asdasdasd"
$("#siparis_Sorgula").click(function(){
$data = $('#siparis_key').val();
$href = $("#siparis_Sorgula").attr('href');
$href = $href+"?key="+$data;
$("#siparis_Sorgula").attr("href", $href);
});
sorgu.php page code
<form action="" method="post" id="jsSorgula">
<div class="row">
<div class="col-lg-12 col-md-12">
<div class="form-group">
<input type="text" name="siparis_key" id="siparis_keyId" placeholder="<?php echo $dil['sipariskodu'] ?>" class="form-control" required>
</div>
</div>
<div class="col-lg-12 col-md-12">
<button type="submit" class="btn btn-primary btn-block"><?php echo $dil['sorgula'] ?></button>
</div>
</div>
</form>
sorgu.php jquery code
<script type="text/javascript">
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
$count = 0;
$(document).ready(function(){
if ($count==0) {
$keys = getUrlVars()["key"];
$('#siparis_keyId').val($keys);
$("#jsSorgula").submit();
$count++;
alert($count);
}
break;
});
The infinity loop could came from your $count = 0. Is set to 0 each time you make a request on that page. Instead of make the validation with count == 0, you should use a method like "on click" or "on change".
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>
I am really new to coding, trying to fix this problem, but I haven't found a solution. Hopefully I can help here. This is the code :
<?php
$stock = file_get_contents("deletedforpost");
$stock2 = file_get_contents("deletedforpost");
$response = json_decode($stock);
foreach ($response as $data) {
$cc = $data->country_code;
$c = $data->country;
$i = $data->invites;
$total += $data->invites; //line 10
$data2 .= "<option value=\"$cc\">$c Remaining: $i</option>"; //line 11
}
if(isset($_POST['k'], $_POST['c'])) {
$key = $_POST['k'];
$country = $_POST['c'];
$upgrade = file_get_contents("deletedforpost");
$upgrade = json_decode($upgrade);
$status = $upgrade->status;
switch ($status){
case "success":
$token = $upgrade->data->token;
$upgrade = $upgrade->data->address;
break;
case "failure":
$failure = $upgrade->message;
break;
default:
$failure = "Unknown Error";
break;
}
}
include'include/header.php';
?>
<section class="bg-primary hero hero-with-header">
<center><div class="container text-white">
<div class="row">
<div class="col-md-12 col-lg-12">
<h1 class="mb-0">You <b>are</b> Here.</h1>
</div>
</div>
</div> </center>
</section>
<section class="bg-primary text-white separator-top">
<div class="container">
<div class="row">
<div class="col-md-6">
<h2>Enter something</h2>
</div>
</div>
<div class="row">
<div class="col">
<form method="post">
<div class="form-row">
<div class="form-group col-md-5 col-lg-6">
<input class="form-control form-control-lg" name="k" placeholder="Your Key">
</div>
<div class="form-group col-md-3 col-lg-4">
<select class="form-control form-control-lg" name="c" id="type-input">
<?=$data2?>
</select>
</div>
<div class="form-group col-md-4 col-lg-2">
<button type="submit" class="btn btn-block btn-lg btn-white">Hello</button>
</div>
</div>
</form>
</div>
</div>
</div>
<?php if ($failure) { //line 88
echo'
<div class="container text-white">
<div class="row">
<div class="col-12 mb-0">
<h2 class="eyebrow mb-2">Output:</h2>
</div>
<div class="col">
<span class="job row align-items-center">
<span class="col-md-6 fs-22 font-weight-light text-white">
Failure!
</span>
<span class="col-md-3">
Upgrade Failed '.$failure.'
</span>
<a target="_blank" href="info.php" class="col-md-3">
Click to get key info!
</a>
</span>
</div>
</div>
</div>
';}
if ($token) { //line 113
echo'
<div class="container text-white">
<div class="row">
<div class="col-12 mb-0">
<h2 class="eyebrow mb-2">Output:</h2>
</div>
<div class="col">
<span class="job row align-items-center">
<span class="col-md-6 fs-22 font-weight-light text-white">
Success!
</span>
<span class="col-md-3">
Address: '.$upgrade.'
</span>
<a target="_blank" href="'.$token.'" class="col-md-3">
Click to accept invite!
</a>
</span>
</div>
</div>
</div>
';} ?>
</section>
<?php include'include/footer.php'?>
I get this following error :
Notice: Undefined variable: total in C:\xampp\htdocs\upgrade.php on line 10
Notice: Undefined variable: data2 in C:\xampp\htdocs\upgrade.php on line 11
Notice: Undefined variable: failure in C:\xampp\htdocs\upgrade.php on line 88
Notice: Undefined variable: token in C:\xampp\htdocs\upgrade.php on line 113
This is my view file here i use 5 search field like product, group, branch, startdate and end date. All are placed in different table. Both were worked nicely and searched nicely but now i want some additional option that is when i select a particular branch in group field dynamically show values based on branch field value. Now it is showing whole data in db.
NOTE: i want this change appear when dropdown select.
<div class="row">
<div class="col-md-12">
<div class="tab-content">
<form method="get" id="frmSearchGroupPur" action="<?php echo
base_url('admin/group/listgroup'); ?>">
<div class="form-body">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Product</label>
<div class="col-md-7">
<?php
$product = array();
// if($data['products']){
// foreach ($data['products'] as
$p)
{
// $product[$p['id']] =
$p['name'];
// }
// }
echo form_dropdown('product', $product,
$data['product'], array('class' => 'form-control
select2','id'=>'product'));
?>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Branch</label>
<div class="col-md-7">
<?php
$branch = array(NULL=>'Any');
if($data['branches']){
foreach ($data['branches'] as $w){
$branch[$w['id']] = $w['name'];
}
}
echo form_dropdown('branch', $branch,
$data['branch'], array('class' => 'form-control','id'=>'branch_dat'));
?>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Group</label>
<div class="col-md-7">
<?php
$group = array(NULL=>'Any');
if($data['groups']){
foreach ($data['groups'] as $g){
$group[$g->id] = $g->name;
}
}
echo form_dropdown('group', $group,
$data['group'], array('class' => 'form-control'));
?>
</div>
</div>
</div>
</div><br/>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Purchase Date From</label>
<div class='input-group date col-md-7'
id='datetimepicker6'>
<?php echo
form_input('fromdate',$data['fromdate'],array('class' => 'form-
control','id'=>'fromdate')); ?>
<span class="input-group-addon">
<span class="glyphicon glyphicon-
calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Purchase Date To</label>
<div class='input-group date col-md-7'
id='datetimepicker7'>
<?php echo
form_input('todate',$data['todate'],array('class' => 'form-
control','id'=>'todate')); ?>
<span class="input-group-addon">
<span class="glyphicon glyphicon-
calendar"></span>
</span>
</div>
</div>
</div>
</div><br/>
<div class="row">
<div class="col-md-4">
<div class="form-group pull-center">
<button type="submit" id="btnFilter" class="btn
btn-info">Submit</button>
<a href="<?php echo
base_url('admin/group/listgroup'); ?>" class="btn btn-default">Reset</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
and my model file to get group is
function getGroupDetails($groupid=0,$state=''){
$this->db->where('id',$groupid);
$this->db->where('branchid',$state);
$query = $this->db->get('group');
if($query->num_rows()==1){
return $query->row_array();
}else{
return FALSE;
}
and my controller function is
function get_group(){
$state=$this->input->post('brch');
$result = $this->model_group->getGroupDetails($state);
// echo json_decode($result);
}
and my not worked jquery file to change group dynamically is below
$('branch_dat').change(function(){
var branch_da=$('#branch_dat').val();
if(branch_da != "")
{
var post_url="admin/sale/get_group";
$('branch_dat').change(function(){
var branch_da=$('#branch_dat').val();
if(branch_da != "")
{
var post_url="admin/sale/get_group";
$.ajax({
type:"POST",
url:post_url,
data:function(params)
{
return{ brch : params.brch};
}
});
}
});