how to fill textbox or paragraph using dropdown from api? - php

I have an API server and want to call the ID with a dropdown and when it is selected. The textbot also changes based on the contents of my API, which ID I choose.
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Code</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<?php foreach($data as $row) : ?>
<a class="dropdown-item" href="#" ><?= $row["Code"]; ?></a>
<?php endforeach ?>
</div>
</div>
<p class="card-text"><?= $row["Desc"] ?></p>
<p class="card-text"><?= $row["LastUpdate"] ?></p>
</div>
help me pls

Related

How to dynamically create a card grid using Foreach in PHP Show 20 records per page

I have a huge list of clients in a table, I have changed the design to boostrabs grids, but now I have a problem and it is that all the contacts are shown in an endless page, it is very long
enter image description here
Php code
<?php if(count($customers)): foreach($customers as $ct): ?>
<div class="row">
<div class="col-xl-3 col-sm-6">
<div class="card">
<div class="card-body">
<div class="dropdown float-end">
<a class="text-muted dropdown-toggle font-size-16" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true"><i class="bx bx-dots-horizontal-rounded"></i></a>
<div class="dropdown-menu dropdown-menu-end"><a class="dropdown-item" href="#">Edit</a><a class="dropdown-item" href="#">Action</a><a class="dropdown-item" href="#">Remove</a></div>
</div>
<div class="d-flex align-items-center">
<div><img src="https://bootdey.com/img/Content/avatar/avatar1.png" alt="" class="avatar-md rounded-circle img-thumbnail" /></div>
<div class="flex-1 ms-3">
<h5 class="font-size-16 mb-1"><?php echo $ct->first_name ?></h5>
<span class="badge badge-soft-success mb-0"><?php echo $ct->dni ?></span>
</div>
</div>
<div class="mt-3 pt-1">
<p class="text-muted mb-0"><i class="mdi mdi-phone font-size-15 align-middle pe-2 text-primary"></i><?php echo $ct->mobile ?></p>
<p class="text-muted mb-0 mt-2"><i class="mdi mdi-email font-size-15 align-middle pe-2 text-primary"></i> <?php echo $ct->gender ?></p>
<p class="text-muted mb-0 mt-2"><i class="mdi mdi-google-maps font-size-15 align-middle pe-2 text-primary"></i><?php echo $ct->company ?>/p>
</div>
<div class="d-flex gap-2 pt-4">
<button type="button" class="btn btn-soft-primary btn-sm w-50"><i class="bx bx-user me-1"></i> Profile</button>
<button type="button" class="btn btn-primary btn-sm w-50"><i class="bx bx-message-square-dots me-1"></i> Contact</button>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="7" class="text-center">No existen Clientes, agregar un nuevo cliente.</td>
</tr>
<?php endif; ?>
</div>
</div>
</div>
</div>
I need 10 contacts to appear per page

when i try to add product in cart the error will show. product will added into cart but cart not shown. Trying to get property 'image' of non-object

the product will be added into the cart but cart due to image error the card will not be shown.
Here is my cart.blade.php file.
#foreach(Cart::instance('cart')->content() as $item)
<li class="pr-cart-item">
<div class="product-image">
<figure><img src="{{asset('assets/images/products')}}/{{$item->model->image}}" alt="{{$item->model->name}}"></figure>
</div>
<div class="product-name">
<a class="link-to-product" href="{{route('product.details',['slug'=>$item->model->slug])}}">{{$item->model->name}}</a>
</div>
<div class="price-field produtc-price"><p class="price">${{$item->model->regular_price}}</p></div>
<div class="quantity">
<div class="quantity-input">
<input type="text" name="product-quatity" value="{{$item->qty}}" data-max="120" pattern="[0-9]*" >
<a class="btn btn-increase" href="#" wire:click.prevent="increaseQuantity('{{$item->rowId}}')"></a>
<a class="btn btn-reduce" href="#" wire:click.prevent="decreaseQuantity('{{$item->rowId}}')"></a>
</div>
<p class="text-center"> Save For Later</p>
</div>
<div class="price-field sub-total"><p class="price">${{$item->subtotal}}</p></div>
<div class="delete">
<a href="#" wire:click.prevent="destroy('{{$item->rowId}}')" class="btn btn-delete" title="">
<span>Delete from your cart</span>
<i class="fa fa-times-circle" aria-hidden="true"></i>
</a>
</div>
</li>
#endforeach
Try something like :
<figure>
<img src="{{asset('assets/images/products/' . $item->model->image)}}" alt="{{$item->model->name}}">
</figure>

php ajax multiple insert ı need

<div class="row">
<?php
$sql=mysqli_query($conn,"select * from is_ilanlari");
while($oku=mysqli_fetch_object($sql))
{
?>
<div class="col-md-4">
<aside class="profile-nav alt">
<section class="card">
<div class="card-header user-header alt bg-dark" >
<div class="media">
<a href="#">
<img class="align-self-center rounded-circle mr-3" style="width:100px; height:100px;" alt="" src="images/korucanta.jpg">
</a>
<div class="media-body">
<h2 class="text-light display-6" style="size:10px;"><?php echo $oku->is_ilanlari_baslik; ?></h2>
<p>Görev süresi : <?php echo $oku->is_ilanlari_bekleme_suresi; ?></p>
<div class="h4 mb-0" style="float:right;"></div>
</div>
</div>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<a href="#"> <i class="fa fa-money"></i><b> Para kazancı </b>
<span class="badge badge-primary pull-right"> <?php echo $oku->is_ilanlari_kazanc; ?></span></a>
</li>
<li class="list-group-item">
<a href="#"> <i class="fa fa-plus-circle"></i><b> XP kazancı </b>
<span class="badge badge-danger pull-right"><?php echo $oku->is_ilanlari_bp; ?></span></a>
</li>
<li class="list-group-item">
<a href="#"> <i class="fa fa-clock-o"></i><b> Görev süresi</b>
<span class="badge badge-danger pull-right" style="background-color:#35dccd; height:28px; text-color:white;">
<p id="kutu1"><?php echo number_format($oku->is_ilanlari_bekleme_suresi); ?></p></span></a>
</li>
<li class="list-group-item">
<form method="POST" id="degerler">
<button type="button" name="buton<?php echo $oku->is_ilanlari_id; ?>" value="<?php echo $oku->is_ilanlari_id; ?>" class="btn btn-secondary btn-lg btn-block">KORUMAYA BAŞLA </button>
</form>
<script>
$(document).ready(function() {
$('button').on('click', function() {
$("button").attr("disabled", "disabled");
var is_id = $(this).val();
if(is_id!=""){
$.ajax({
url: "isbaslat.php",
type: "POST",
data: {
is_id: is_id
},
cache: false,
success: function(dataResult){
var dataResult = JSON.parse(dataResult);
if(dataResult.statusCode==1){
//$("button").removeAttr("disabled");
$('#degerler').find('input:text').val('');
$("#success").show();
$('#success').html('İş Başladı !');
console.log("b");
}
else if(dataResult.statusCode==0){
alert("Error occured !");
}
}
});
}
else{
alert('Please fill all the field !');
}
});
});
</script>
</li>
</ul>
</section>
</aside>
</div>
<?php
}
?>
</div>
this is form create php and ajax
can you see ?
<?php
session_start();
include('baglanti.php');
include('fonksiyonlar.php');
$kid=$_SESSION['kullanici_adi'];
getir_kullanici($kid);
$k_id=$getir['kid'];
$is_id=$_POST['is_id'];
$sql = "insert into kullanici_is(is_ilan_id,kullanici_id,is_baslangic_tarih,is_durum)
values ('$is_id','$k_id','".date("Y-m-d H:i:s")."',1)";
if (mysqli_query($conn, $sql)) {
echo json_encode(array("statusCode"=>1));
}
else {
echo json_encode(array("statusCode"=>0));
}
mysqli_close($conn);
?>
this is insert php you can see
http://prntscr.com/rhrmp5
ı want to insert a line.But this buttons all of them click and inserted 8 line in database.
How ı can insert just clicked value.
ı tryed all things pls help me
ı try again but no ı can t do it pls help me ı need more help . ı am waiting for
issue: code inside loop
Solution: move js code outside loop to avoid multiple instances,
use a class for all buttons
$('.btn_class').on('click', function() {
// now only the specific btn is clicked
$(this).val(); // will be of the clicked btn
...
}
add btn class
<form method="POST" id="degerler">
<button type="button" name="buton<?php echo $oku->is_ilanlari_id; ?>" value="<?php echo $oku->is_ilanlari_id; ?>" class="btn btn-secondary btn-lg btn-block btn_class">KORUMAYA BAŞLA </button>
</form>
fixed :
<div class="row">
<?php
$sql=mysqli_query($conn,"select * from is_ilanlari");
while($oku=mysqli_fetch_object($sql))
{
?>
<div class="col-md-4">
<aside class="profile-nav alt">
<section class="card">
<div class="card-header user-header alt bg-dark" >
<div class="media">
<a href="#">
<img class="align-self-center rounded-circle mr-3" style="width:100px; height:100px;" alt="" src="images/korucanta.jpg">
</a>
<div class="media-body">
<h2 class="text-light display-6" style="size:10px;"><?php echo $oku->is_ilanlari_baslik; ?></h2>
<p>Görev süresi : <?php echo $oku->is_ilanlari_bekleme_suresi; ?></p>
<div class="h4 mb-0" style="float:right;"></div>
</div>
</div>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<a href="#"> <i class="fa fa-money"></i><b> Para kazancı </b>
<span class="badge badge-primary pull-right"> <?php echo $oku->is_ilanlari_kazanc; ?></span></a>
</li>
<li class="list-group-item">
<a href="#"> <i class="fa fa-plus-circle"></i><b> XP kazancı </b>
<span class="badge badge-danger pull-right"><?php echo $oku->is_ilanlari_bp; ?></span></a>
</li>
<li class="list-group-item">
<a href="#"> <i class="fa fa-clock-o"></i><b> Görev süresi</b>
<span class="badge badge-danger pull-right" style="background-color:#35dccd; height:28px; text-color:white;">
<p id="kutu1"><?php echo number_format($oku->is_ilanlari_bekleme_suresi); ?></p></span></a>
</li>
<li class="list-group-item">
<form method="POST" id="degerler">
<button type="button" name="buton<?php echo $oku->is_ilanlari_id; ?>" value="<?php echo $oku->is_ilanlari_id; ?>" class="btn btn-secondary btn-lg btn-block">KORUMAYA BAŞLA </button>
</form>
</li>
</ul>
</section>
</aside>
</div>
<?php
}
?>
</div>
// move script outside the loop
<script>
$(document).ready(function() {
$('button').on('click', function() {
$("button").attr("disabled", "disabled");
var is_id = $(this).val();
if(is_id!=""){
$.ajax({
url: "isbaslat.php",
type: "POST",
data: {
is_id: is_id
},
cache: false,
success: function(dataResult){
var dataResult = JSON.parse(dataResult);
if(dataResult.statusCode==1){
//$("button").removeAttr("disabled");
$('#degerler').find('input:text').val('');
$("#success").show();
$('#success').html('İş Başladı !');
console.log("b");
}
else if(dataResult.statusCode==0){
alert("Error occured !");
}
}
});
}
else{
alert('Please fill all the field !');
}
});
});
</script>

Bootstrap 3 dropdown button height and search

I'm having a little problem with bootstrap 3. I tried for the whole day to solve and searched everything in internet even used FireBug but didn't help.
The button of dropdown is higher than the menu and its going outside the menu.
<ul class="nav navbar-nav navbar-right">
<?php if(!is_array(session( 'thisUser'))): ?>
<span class="glyphicon glyphicon-user"></span> <?php echo T('Register') ?>
<span class="glyphicon glyphicon-log-in"></span> <?php echo T('Login') ?>
<?php else: ?>
<li class="dropdown">
<a class="dropdown-toggle text-notransform" data-toggle="dropdown" href="#">
<img src="<?php echo URL(session_get('preferences', 'avatar')) ?>" width="24px">
<?php echo session_get('thisUser', 'username') ?> <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<div class="navbar-login">
<div class="row">
<div class="col-lg-4">
<p class="text-center">
<img src="<?php echo URL(session_get('preferences', 'avatar')) ?>" width="200px">
</p>
</div>
<div class="col-lg-8">
<p class="text-left"><strong><?php echo session_get('thisUser', 'username') ?></strong>
</p>
<p class="text-left small">
<?php echo session_get( 'thisUser', 'email') ?>
</p>
<br />
<p class="text-left">
<a href="<?php echo URL(T('setting-slug', 'settings')) ?>" class="btn btn-primary btn-block btn-sm">
<?php echo T( 'Settings') ?>
</a>
<?php echo event( 'user_menu', '') ?>
</p>
</div>
</div>
</div>
</li>
<li class="divider"></li>
<li>
<div class="navbar-login navbar-login-session">
<div class="row">
<div class="col-lg-12">
<p>
<a href="<?php echo URL('logout') ?>" class="btn btn-danger btn-block">
<?php echo T( 'Logout') ?>
</a>
</p>
</div>
</div>
</div>
</li>
</ul>
</li>
</ul>
<?php endif; ?>
</ul>
My second problem is with the bootstrap search I want the button search to be next to the search text not bellow it. The code is PHP function:
function search_box($a){
$return .= Form::open(array('method'=>'GET', 'action'=>URL(T('directory'))));
$return .= Form::input('q', R('q'), array('class'=>'form-control input-md', 'style'=>'margin-bottom:5px','placeholder'=>T('Type smth to search')));
$return .= '<button type="submit" class="btn btn-block btn-md btn-primary"><i class="icon-find"></i> '.T('Search').'</button>';
$return .= Form::close();
$return .= '<div class="clearfix"><br /></div>';
return $return;
}
(For image of the search is the same as the above link)
Can someone tell me how to fix this. Thanks in advance.
On your searchbox($a) function, try removing btn-md class from button.

How do I assign click events and IDs to multiple buttons in twitter bootstrap?

I currently have multiple drop down buttons for several table rows that need to be tied to an onClick event. The problem I'm having is capturing the information from each button. Here is what my test code looks like:
<table class="table table-bordered">
<tbody>
<tr>
<td><img src="/photos/files/5/m/131309a4fb918110ed1061e90a715eca.jpeg"/></td><td><div class="btn-group">
<a class="btn btn-primary" href="#"><i class="icon-user icon-white"></i> User</a>
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><i class="icon-pencil"></i> Edit</li>
<li><i class="icon-trash"></i> Delete</li>
</ul>
</div>
</tr>
<tr>
<td><img src="/photos/files/5/m/b19102d8ba1158e2a139ffa84e8e8540.jpeg"/></td><td><div class="btn-group">
<a class="btn btn-primary" href="#"><i class="icon-user icon-white"></i> User</a>
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><i class="icon-pencil"></i> Edit</li>
<li><i class="icon-trash"></i> Delete</li>
</ul>
</div></tr>
</tbody>
</table>
current javascript:
$('.btn').click(function(e) {
e.preventDefault();
???
});
How do I capture and process each click event from multiple buttons? I'm assuming I need to add a unique ID to each button but how can I capture an onclick event for each button item?
inside the function you can use this to reffer to the object in cause.
$(".btn").click(function () {
//here you can check which button did it
if ($(this).attr('class')=='icon-pencil')
//do sth
else
//do sth else
});
Check the jquery docs.

Categories