I am using load more functionality in my application using jQuery ajax. This is my ajax code:
$(document).ready(function() {
$(document).on('click','.show_more', function(e) {
e.preventDefault();
var ID = $(this).attr('id');
//$('.show_more').hide();
//$('.loding').show();
alert(ID)
$.ajax({
type:'POST',
url:'ajax_load_more.php',
data:{"id" : ID},
success:function(html){
$('#show_more_main'+ ID).remove();
$('.showmorediv').append(html);
}
});
e.preventDefault();
});
For testing i put alert to display id it working perfectly. But ajax code is not working.there is no error and no console log found.
i double check ajax_load_more.php page it working perfectly according to alerted id.
Here is my php code
if(isset($_POST["id"]) && !empty($_POST["id"]))
{
$queryAll = $conn->query("SELECT COUNT(*) as num_rows FROM product WHERE id < ".$_POST['id']." ORDER BY id DESC");
$row = $queryAll->fetch_array();
$allRows = $row['num_rows'];
$showLimit = 3;
$query2 = $conn->query("SELECT * FROM product WHERE id < ".$_POST['id']." ORDER BY id DESC LIMIT ".$showLimit);
$rowCount = $query2->num_rows;
if($rowCount > 0){
while($row_p = $query2->fetch_array()){
$loadmoreid = $row_p["id"]; ?>
<div class="col-md-4 col-sm-6 col-xs-12 mar-bot showmorediv">
<!-- single-product-start -->
<div class="single-product">
<div class="single-product-img">
<a href="product-details/<?=preg_replace('!\s+!', '-',preg_replace("/[^A-Za-z0-9 \s+]/",' ',$row_p[4]));?>-<?=$row_p[0];?>">
<img src="<?=$row_p[13];?>" alt="<?=$row_p[3];?>"/>
</a>
<span class="sale-box">
<span class="sale">-<?php echo $offprice=round((($row_p[5]-$row_p[6])*100)/$row_p[5]); ?>%</span>
</span>
</div>
<div class="single-product-content">
<div class="product-title">
<h5>
<?=$row_p[3];?>
</h5>
</div>
<div class="price-box">
<span class="price">Rs.<?=$row_p[6];?></span>
<span class="old-price">Rs.<?=$row_p[5];?></span>
</div>
<div class="product-action">
<button class="btn btn-default add-cart" data-id="<?=$row_p[0];?>" data-name="<?=$row_p[3];?>" data-summary="<?=$row_p[3];?>" data-price="<?=$row_p[6];?>" data-quantity="1" data-image="<?=$row_p[13];?>">Add to cart</button>
</div>
</div>
</div>
</div>
<?php
}
if($allRows > $showLimit)
{
?>
<div class="show_more_main" id="show_more_main<?php echo $loadmoreid; ?>">
<span id="<?php echo $loadmoreid; ?>" class="show_more btn btn-primary" title="Load more posts btn btn-primary">More</span>
<span class="loding" style="display: none;"><span class="loding_txt">Loading…</span></span>
</div>
<?php }
}
}
?>
You can get the unknown error by using jquery ajax error function as like this
https://stackoverflow.com/a/8918298/7419418
Related
I have a list of product in a cart. Now, i want to calculate all of the product price in cart. But i still didn't get how to get and calculate the value from dynamic element. Here's my code for the dynamic product in a cart:
<div class="modal fixed-right fade" id="modalShoppingCart" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-vertical" role="document">
<div class="modal-content">
<ul class="list-group list-group-lg list-group-flush">
<?php
$no = 1;
$query = mysqli_query($con, "SELECT c.id, c.quantity, c.product_id, p.name, p.thumbnail, p.sale_price FROM cart AS c LEFT JOIN product AS p ON c.product_id= p.id LEFT JOIN user AS u ON c.user_id=u.id WHERE c.product_id = p.id GROUP BY p.id")or die(mysqli_error($con));
while($data = mysqli_fetch_array($query)){
$product_id = $data['product_id'];
$sql = mysqli_query($con, "SELECT COUNT(product_id) FROM cart WHERE product_id='$product_id' GROUP BY product_id ");
$row = mysqli_fetch_array($sql);
$quantity = $row['COUNT(product_id)'];
$sale_price = (int)$data['sale_price'] * $quantity;
?>
<li class="list-group-item">
<div class="row align-items-center">
<div class="col-4">
<a href="product.html">
<img class="img-fluid" src="../assets/img/<?php echo $data['thumbnail']; ?>" alt="...">
</a>
</div>
<div class="col-8">
<p class="font-size-sm font-weight-bold mb-6">
<a class="text-body" href="product.php"><?php echo $data['name']; ?></a> <br>
<span class="text-muted"><?php echo 'Rp'.(str_replace(',', '.', number_format($sale_price))) ?? 'Rp0'; ?></span>
<input type="hidden" name="sale_price" class="sale_price<?php echo $no++; ?>" value="<?php echo $sale_price; ?>">
</p>
<div class="d-flex align-items-center">
<input type="number" class="d-inline-block form-control form-control-xxs w-auto m-width-65" name="quantity" value="<?php echo $quantity; ?>">
<a class="font-size-xs text-gray-400 ml-auto" href="hapus-produk-cart.php?id=<?php echo $data['id']; ?>">
<i class="fe fe-x"></i> Hapus
</a>
</div>
</div>
</div>
</li>
<?php } ?>
</ul>
<div class="modal-footer line-height-fixed font-size-sm bg-light mt-auto">
<strong>Total</strong> <strong class="ml-auto"></strong>
</div>
<div class="modal-body">
<a class="btn btn-block btn-dark" href="checkout.php">Checkout Pesanan</a>
</div>
</div>
</div>
</div>
since the products is dynamic, i didn't know how to get the value in <input type="hidden" name="sale_price" class="sale_price<?php echo $no++; ?>" value="<?php echo $sale_price; ?>">. and how to calculate it using jQuery or javascript. Would u help me how to do that? I really need your help guys. Thank you in advance.
Where to start? I am not going to deal with the need to use prepared statements but I suggest you do some reading about SQL injection. So, let's try starting with your first query -
SELECT c.id, c.quantity, c.product_id, p.name, p.thumbnail, p.sale_price
FROM cart AS c
LEFT JOIN product AS p ON c.product_id= p.id
LEFT JOIN user AS u ON c.user_id=u.id
WHERE c.product_id = p.id
GROUP BY p.id
Why the LEFT joins? These should be INNER joins, surely? Why join to the user table at all if it is not being returned in the SELECT list? This current query is going to return all carts with their respective products and users. Probably not what you intended. Maybe you want the cart and associated products for the current user? I will continue on this basis.
SELECT c.id, c.quantity, c.product_id, p.name, p.thumbnail, p.sale_price, c.quantity * p.sale_price AS line_item_total
FROM cart AS c
JOIN product AS p ON c.product_id= p.id
WHERE c.user_id = ? /* where ? is the current user's id */
I have taken the liberty of modifying the query to get the db to return the line_item_total for us.
And now onto the second query, run for each record returned by first query -
SELECT COUNT(product_id)
FROM cart
WHERE product_id='$product_id'
GROUP BY product_id
I am not quite sure what this is supposed to be doing but it won't work as you expect. It will return the COUNT of users who have this product_id in their cart. The only relevant quantity should be the one already returned by your cart query.
This is definitely not beautiful but it should be enough to get you started -
<?php
$current_user_id = 1; // coming from session or ...
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect('host', 'user', 'pass', 'db');
/* This is a very crude piece of code to handle the AJAX request. The user_id
* predicate in the UPDATE query is really important to stop people modifying
* the request to update someone else's cart */
if (isset($_POST['action']) && $_POST['action'] == 'updateCartItem') {
// Notice the three placeholders used for the prepared statement
$stmt = mysqli_prepare($link, 'UPDATE cart SET quantity = ? WHERE id = ? AND user_id = ?');
mysqli_stmt_bind_param($stmt, 'iii', $_POST['quantity'], $_POST['id'], $current_user_id);
mysqli_stmt_execute($stmt);
echo (mysqli_affected_rows($link) == 1) ? 'success' : 'failure';
die;
}
/* Query to retrieve cart and associated products for given user_id */
$sql = 'SELECT c.id, c.quantity, c.product_id, p.name, p.thumbnail, p.sale_price, c.quantity * p.sale_price AS line_item_total
FROM cart AS c
JOIN product AS p ON c.product_id = p.id
WHERE c.user_id = ?';
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_bind_param($stmt, 'i', $current_user_id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$cart_items = mysqli_fetch_all($result, MYSQLI_ASSOC);
?>
<div class="modal fixed-right fade" id="modalShoppingCart" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-vertical" role="document">
<div class="modal-content">
<ul class="list-group list-group-lg list-group-flush">
<?php $cart_total = 0; foreach ($cart_items as $cart_item): ?>
<li class="list-group-item cart-item">
<span class="cart-item-id"><input type="hidden" name="id" value="<?php echo $cart_item['id']; ?>"></span>
<span class="cart-item-img"><img src="../assets/img/<?php echo $cart_item['thumbnail']; ?>"></span>
<span class="cart-item-name"><?php echo $cart_item['name']; ?></span>
<span class="cart-item-price"><?php echo $cart_item['sale_price']; ?></span>
<span class="cart-item-quantity"><input type="number" name="quantity[<?php echo $cart_item['product_id']; ?>]" value="<?php echo $cart_item['quantity']; ?>"></span>
<span class="cart-item-total"><?php echo $cart_item['line_item_total']; ?></span>
</li>
<?php $cart_total += $cart_item['line_item_total']; endforeach; ?>
</ul>
<div class="modal-footer line-height-fixed font-size-sm bg-light mt-auto">
<strong>Total</strong> <span id="cart-total-price" class="ml-auto"><?php echo $cart_total; ?></span>
</div>
<div class="modal-body">
<a class="btn btn-block btn-dark" href="checkout.php">Checkout Pesanan</a>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('.cart-item-quantity input').change(function() {
updateQuantity(this);
});
/* Update quantity */
function updateQuantity(quantityInput) {
/* Calculate line price */
var productRow = $(quantityInput).closest('li.cart-item');
var cartItemId = productRow.find('.cart-item-id input').val();
var price = parseFloat(productRow.find('span.cart-item-price').text());
var quantity = $(quantityInput).val();
var linePrice = price * quantity;
productRow.find('span.cart-item-total').text(linePrice.toFixed(2));
/* Send AJAX request to update line item */
$.post( '', { action: 'updateCartItem', id: cartItemId, quantity: quantity })
.done(function( data ) {
/* Their should be proper handling of the response here */
console.log( "Result: " + data );
});
updateCart();
}
function updateCart() {
var cartTotal = 0;
$('span.cart-item-total').each(function () {
cartTotal += parseFloat($(this).text());
});
$('span#cart-total-price').text(cartTotal.toFixed(2));
}
});
</script>
$query = "select * from comments t1 inner join users t2 on t1.user_id = t2.UserId where usercomplain_id='$id'";
$run =mysqli_query($mysqli,$query);
while($row=mysqli_fetch_array($run))
{
$commentid = $row['comment_id'];
$comment = $row['comment'];
$username = $row['UserName'];
$userid1 = $row['UserId'];
$date = $row['CDate'];
$ageDate = time_elapsed_string($date);
?>
<div class="jumbotron" style="border:3px solid #2FAB9B; background-color:#68C8C6;">
<div class="row">
<div class="col-md-10">
<?php echo $comment; ?>
</div>
<div class="col-md-2">
<?php echo $ageDate; ?>
</div>
</div>
<br>
<label>Comment by <?php echo $username; ?></span></label><br>
<a class="reply" data-role="<?php echo $commentid; ?>">Reply</a>
<br>
<br>
<div style="width:63%; display:none;" class="replyForm" data-role="<?php echo $commentid; ?>">
<form method="post">
<textarea cols="100" rows="4"></textarea><br>
<br>
<input type="submit" name="reply" class="btn btn-primary" style="float:right" value="reply">
</form>
</div>
</div>
<script>
$(document).ready(function(){
$(".reply").click(function(){
var current = $(this).attr("data-role");
$('.replyForm[data-role="'+$(this).attr("data-role")+'"]').fadeIn();
});
});
</script>
<?php
if(isset($_POST['reply']))
{
echo "<script>alert('$commentid')</script>";
}
?>
<?php } ?>
it is a simple comment system with each comment there is a reply link on click on reply link a textbox is shown . I want to enter comment reply to database table therefore I want to get the record of the specific comment. How to do that with PHP.
this code should do what you want, completely dinamically
<div class="jumbotron comment-container" data-pk="<?php echo $commentid; ?>">
<div class="row">
<div class="col-md-10">
<?php echo $comment; ?>
</div>
<div class="col-md-2">
<em class="text-muted"><?php echo $ageDate; ?></em>
</div>
<div class="col-md-12">
<label>Comment by <?php echo $username; ?></label><br/>
<button class="btn btn-primary reply">Reply</button>
</div>
</div>
</div>
And here is the JS part. In order to reduce the code printed in the while loop, the reply form is cloned each time and appended where needed.
var reply_form = $('<div class="row replyForm-container"><div class="col-md-12">'+
'<form method="post" class="reply-form">'+
'<textarea class="form-control" rows="4">Prefilled content</textarea><br>'+
'<br>'+
'<button type="submit" name="reply" class="btn btn-primary" style="float:right" >Reply</button>'+
'</form>'+
'</div></div>');
$(".reply").click(function(){
$(this).hide();
var $container = $(this).closest('.comment-container');
var pk = $container.data('pk');
var rf_clone = reply_form.clone();
rf_clone.find('form').attr('data-pk', pk).data('pk', pk);
$container.append( rf_clone.hide().fadeIn(1000) );
});
// working with dynamical elements, we need to use delegation here
$(document).on('submit', '.reply-form', function(e){
e.preventDefault();
var reply_container = $(this).closest('.replyForm-container');
var pk = $(this).data('pk');
var reply = $(this).find('textarea').val();
console.log('Insert reply "'+reply+'" for comment ID: '+pk);
$.ajax({
type: "POST",
url: 'my_php_handler.php',
async: false,
dataType: "json",
data: {action: 'add-reply', commend_id: pk, reply_text: reply},
success: function (response) {
if( response ) {
reply_container.fadeOut('slow', function(){
var btn = reply_container.closest('.comment-container').find('button.reply');
$(this).remove(); //will remove the element after fadeOut completes
btn.show();
})
}
}
});
});
Check working Fiddle (ajax disabled)
HERE IS THE CODE I'M USING TO UPDATE THE COUPON COUNT.
<div id="click" class="coupon-detail coupon-button-type">
<a href="#" class="coupon-button coupon-code" data-aff-url="https://example.com">
<span class="code-text">CODE</span>
<span class="get-code">Get Code</span>
</a>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="coupon-footer coupon-listing-footer">
<ul class="clearfix">
<script type="text/javascript">
$(document).ready(function(e) {
$('#click').click(function(){
<?php
$update = "UPDATE coupon_stats SET today = today + 1";
$query_coupon = mysqli_query($con , $update)or die(mysqli_error($con));
?>
})
});
</script>
<?php
$select = "SELECT * FROM coupon_stats";
$query_select = mysqli_query($con,$select);
$data = mysqli_fetch_assoc($query_select);
?>
<li><span><i class="wifi icon"> </i> <?php echo $data['today'].' Coupon Used'; ?>
</span>
</li>
but my coupon count is getting +1 whenever I refresh the page instead of clicking on the button.
I'm not getting an idea. What am I doing wrong?
Can anyone help me to solve this?
This should do what you need.
We set data: 1 in the ajax request, so you can perform a check when the page loads if(isset($_POST['data])) on the process_request.php file.
<div id="click" class="coupon-detail coupon-button-type">
<a href="#" class="coupon-button coupon-code" data-aff-url="https://example.com">
<span class="code-text">CODE</span>
<span class="get-code">Get Code</span>
</a>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="coupon-footer coupon-listing-footer">
<ul class="clearfix">
<?php
$select = "SELECT * FROM coupon_stats";
$query_select = mysqli_query($con,$select);
$data = mysqli_fetch_assoc($query_select);
?>
<li>
<span>
<i class="wifi icon"></i> <?php echo $data['today'].' Coupon Used'; ?>
</span>
</li>
<script>
$(document).ready(function(e) {
$('#click').click(function(){
$.ajax({
url : "process_request.php",
type: "POST",
data: {data: 1},
success: function(data, textStatus, jqXHR)
{
//data - response from server
},
error: function (jqXHR, textStatus, errorThrown)
{
}
});
})
});
</script>
In process_request.php
<?php
//Add db connection details
if(isset($_POST['data'])){
$update = "UPDATE coupon_stats SET today = today + 1";
$query_coupon = mysqli_query($con , $update)or die(mysqli_error($con));
}
?>
You can go further and add a response from process_request.php and then handle that in the success function of AJAX.
I have a dynamic form for Product Orders. I am setting the price based on company(select2) and product using onchange from the product dropDownList. Company is on the base form outside the dynamicform (easy to reference) but product is a list item within the dynamicform. My code is working for the first item but I cannot set the subsequent because I cannot figure out how to address the item # of the added dynamic form items.
dynamic form loop:
<?php foreach ($modelsOrderItem as $o => $modelOrderItem): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="clearfix"></div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $modelOrderItem->isNewRecord) {
echo Html::activeHiddenInput($modelOrderItem, "[{$o}]id");
}
?>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="col-md-5">
<?= $form->field($modelOrderItem, "[{$o}]idProduct")->
dropDownList
(
ArrayHelper::map(Product::find()->all(), 'id','ProductCodeWithName'),
['prompt' => 'Select a Product','style'=>'width:400px' ,
'onchange' => '$.post( "index.php?r=pricelist/pricelist&idProduct='.'"+$(this).val()+"'.'&idCompany='.'"+$("#order-idcompany").val(),
function(data)
{
$( "#orderitem-0-itemprice" ).val(data);
});']
)->label(false);
?>
</div>
<div class="col-md-3" >
<?= $form->field($modelOrderItem, "[{$o}]itemQuantity")->textInput(['style'=>'width:150px'])->label(false) ?>
</div>
<div class="col-md-2">
<?= $form->field($modelOrderItem, "[{$o}]itemPrice")->textInput(['style'=>'width:200px'])->label(false) ?>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
I have now removed the onchange function and added Javascript that allows me to control which form element to change but, I cannot figure out how to do this with dynamically added elements. I have included script looking for a change in the added price element but the script does not get activated. So it works for the zero(0) element but will not respond with orderitem1, etc. Here is my updated code and the Javascript.
<div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelsOrderItem as $o => $modelOrderItem):?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="clearfix"></div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $modelOrderItem->isNewRecord)
{
echo Html::activeHiddenInput($modelOrderItem, "[{$o}]id");
}
?>
<div class="form-group kv-fieldset-inline">
<div class="col-sm-4">
<?= $form->field($modelOrderItem, "[{$o}]idProduct")->dropDownList
(
ArrayHelper::map(Product::find()->orderBy('productCode')->all(), 'id','ProductCodeWithName'),
['prompt' => 'Select a Product','style'=>'width:360px' ,]
)->label(false);
?>
</div>
<div class="col-sm-2" >
<?= $form->field($modelOrderItem, "[{$o}]itemQuantity")->textInput(['style'=>'width:100px','padding'=>'100px'])->label(false) ?>
</div>
<div class="col-sm-2" >
<?= $form->field($modelOrderItem, "[{$o}]quantityType")->DropdownList(['Cartons'=>'Cartons','Bags'=>'Bags','Kilograms'=>'Kilograms',
'Tubs'=>'Tubs', 'Pieces' => 'Pieces'],['style'=>'width:150px'])->label(false) ?>
</div>
<div class="col-sm-2">
<?= $form->field($modelOrderItem, "[{$o}]itemPrice")->textInput(['style'=>'width:200px'])->label(false) ?>
</div>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
</div>
Javascript:
<?php
$script = "$('#orderitem-0-idproduct').change(function()
{
var idProduct = $(this).val();
$.get( 'index.php?r=pricelist/getpricelist&idProduct',{ idProduct:idProduct, idCompany:$model->idCompany },
function(data)
{
$('#orderitem-0-itemprice').val(data);
});
});
$('#orderitem-1-idproduct').change(function()
{
var idProduct1 = $(this).val(data);
alert();
$.get( 'index.php?r=pricelist/getpricelist&idProduct',{ idProduct:idProduct1, idCompany:$model->idCompany },
function(data)
{
$('#orderitem-1-itemprice').val(data);
});
});";
$this->registerJs($script);
?>
I was able to use Javascript to find out which element was being clicked. This avoided the problem of being able to run code on dynamic elements that had not been initiated.
<?php $js = <<<JS
$('body').change(function(e)
{
var element = '#'+$(e.target).attr('id');
var field = element.substring(element.length - number_of_chars_in_your_fieldname, element.length); //stripping the string to identify the field you are looking
if(field === "field_you_are_looking_for") //element usually looks like #formID-row-field
{
var dropdownID = $(element).val();
if (element.length === 22) //single digit row numbers
{
var row = element.substring(11,12); //extract the current row number
} else //row numbers higher than 9
{
var row = element.substring(11,13);
}
//Do whatever you need to do
$('#formID-'+row+'-field_you_want_to_change').val(data); //set the field to change on current row
}
});
JS;
$this->registerJs($js);
?>
i'm using a Filter in which i use the Form..When a user a land on the list page it should automatically submit the form so user can get values only he want to see. i have tried a lot of things like jquery JS and using snippet in body but none of them is working. For the following code the form keep on submitting.
<div class="container shop-filter">
<div class="filter">
<form action="" method="POST" enctype="multipart-form-data" id="city-filter" name="cit-filter">
<select name="filter" id="select">
<option value="all">All city</option>
<?php
$sql="SELECT * FROM tcity";
$connect= mysqli_query($conn, $sql) or die ("Failed To Connect.");
while($rows= mysqli_fetch_array($connect, MYSQLI_ASSOC)){ ?>
<option value= "<?php echo $rows['c_id']?>" id="optin_val" <?php echo (!empty($_COOKIE['dropdown']) && $_COOKIE['dropdown'] == $rows['c_id'] ? 'selected' : ''); ?>><?php echo $rows['city_nm'];?></option>
<?php }
?>
</select>
<input type="submit" name="submitt" id="submitt" value="filter" class="btn .btn-default">
</form>
</div>
<div class="view">
<i class="fa fa-th fa-lg" aria-hidden="true"></i><span id="grid-view"> Grid</span>
<i class="fa fa-th-list fa-lg" aria-hidden="true"></i><span id="list-view"> list</span>
</div>
<hr id="hr-1" style="width:100%">
</div>
<div class="container blocks" id="content">
<?php
//Grab the variable sent through link by sub_category.php
//session_start();
$subcategory_id='';
$subcategory_id= $_GET['sub_id'];
$_SESSION['sub'] = $subcategory_id;
$row_count = 0;
if(isset($_POST['submitt'])){
$city_id=$_POST['filter'];
if($city_id == 'all'){
$sql="SELECT * FROM tadd WHERE sub_id = '$subcategory_id' ORDER BY add_nm";
}else{
$sql="SELECT * FROM tadd WHERE sub_id = '$subcategory_id' AND c_id = '$city_id' ORDER BY add_nm";
}
}else{
$sql="SELECT * FROM tadd WHERE sub_id = '$subcategory_id' ORDER BY add_nm";
}
//$sql="SELECT * FROM tadd WHERE sub_id = '$subcategory_id' AND c_id = '$city_id'";
$conection = mysqli_query($conn, $sql);
while ($rows = mysqli_fetch_array($conection, MYSQLI_ASSOC)){
$name = $rows['add_nm'];
$add_id = $rows['add_id'];
//get the join date and Expiry date to hide Expired Contents
$current_date = strtotime(date('Y-m-d'));
$exp = strtotime($rows['exp_dt']);
$row_count = mysqli_num_rows($conection);
//get Images
//$shop_image = trim($add_id.'.jpg');
?>
<!-- Do Not Show Expired Contents -->
<?php if( $current_date <= $exp ) {?>
<div class="dialog">
<div class="shop_img">
<img src="../image/shops/1.jpg" alt ="<?php echo $name;?>" >
</div>
<hr id="hr">
<div class="shop_name">
<?php echo strtoupper($name);?>
</div>
<a href="detail.php?add=<?php echo $add_id;?>"><div class="address">
<span id="1">ADDRESS</span><span id="2"><i class="fa fa-arrow-right" aria-hidden="true"></i></i></span>
</div></a>
</div>
<?php
}
}
if( $row_count == 0 ){
echo '<div class ="msg">Sorry! No Entries Found.</div>';
}
?>
</div>
</body>
<footer>
<?php
include("../footer.html");
?>
</footer>
<script>
$(document).ready(function(){
$("#city-filter").submit();
})
</script>
As i shown in image when user comes to this page it has to show only success classes. But it is showin all...when i hot filter it'll show currect.so i want to cancel hiting submit manually and auto submit the form
You could put it inside a condition to check if there are some dialog divs:
$(document).ready(function(){
if($('.dialog').length === 0 ){ // check the length of dialog div if 0
$("#city-filter")[0].submit(); // then only submit the form
}
})
Instead use the native .submit() event on the form.