Load my php script only once the page load - javascript

I am creating a shopping website where this it the page where product shows up.
now i want to add sorting functionality by color but issue comes when the page load only first mysql query run not any other this happens every time the page loads.
This php script create multiple div in row, what I want to do is run $query only once but when the page reload second time those div does not show up.
I want to this because I want to run other mysql query after the page reload.
<?php
//get rows query
$query = $db->query("SELECT pd.Product_Details_ID,pd.Slide_Photos,pd.rate,pm.Product_Name,pm.Product_ID,pm.gender from product_details as pd INNER JOIN product_master as pm ON pd.Product_ID=pm.Product_ID where pm.gender='$gender' ");
if ($query->num_rows > 0) {
while ($row = $query->fetch_assoc()) {
?>
<div class="col-sm-4 ">
<div class="productBox">
<div class="productImage clearfix">
<img src="<?php echo $row["Slide_Photos"]; ?>" alt="products-img">
<div class="productMasking">
<ul class="list-inline btn-group" role="group">
<li><a class="btn btn-default btn-wishlist"><i class="fa fa-heart-o"></i></a></li>
<li><i class="fa fa-shopping-basket"></i></li>
<li><a class="btn btn-default" href="product_info.php?Product_Details_ID=<?php echo $row["Product_Details_ID"]; ?>"><i class="fa fa-eye"></i></a></li>
</ul>
</div>
</div>
<div class="productCaption clearfix">
<a href="single-product.html">
<h5><?php echo $row['Product_Name']; ?> <?php echo $row["Product_Details_ID"]; ?></h5>
</a>
<h3><?php echo $row["rate"]; ?></h3>
</div>
</div>
</div>
<?php }
} else { ?>
<p>Product(s) not found.....</p>
<?php } ?>

Related

How do I get code to show only images uploaded by current user? P.s. New to programming

The following code displays all users images that is uploaded to the database instead of the current user that is logged in. I've tried to retrieve the user specific uploaded pics with 'userCustomerID
As per the title, how do I get code to show only images uploaded by current user?
<div class="row">
<?php
$stmt = $DB_con->prepare('SELECT userID, userName, userItemName, userItemPrice, userItemQuantity, userItemDetails, userCustomerID, userPic FROM upload_tbl_users ORDER BY userCustomerID DESC');
$stmt->execute();
if($stmt->rowCount() > 0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
?>
<div class="col-xs-3">
<p class="page-header"><?php echo $userName." / ".$userItemName; ?></p>
<a target="_blank" href="user_images/<?php echo $row['userPic']; ?>" />
<img src="user_images/<?php echo $row['userPic']; ?>" class="img-rounded" width="250px" height="250px" />
<p class="page-header">
<span>
<a class="btn btn-info" href="editform.php?edit_id=<?php echo $row['userCustomerID']; ?>" title="click for edit" onclick="return confirm('sure to edit ?')"><span class="glyphicon glyphicon-edit"></span> Edit</a>
<a class="btn btn-danger" href="?delete_id=<?php echo $row['userCustomerID']; ?>" title="click for delete" onclick="return confirm('sure to delete ?')"><span class="glyphicon glyphicon-remove-circle"></span> Delete</a>
</span>
</p>
</div>
<?php
}
}
else
{
?>
<div class="col-xs-12">
<div class="alert alert-warning">
<span class="glyphicon glyphicon-info-sign"></span> No Data Found ...
</div>
</div>
<?php
}
?>
</div>
Then I guess you have to get the id of logged user and add a WHERE clause in your sql script. Like:
SELECT...WHERE logged_user_id=uploaded_user_id
uploaded_user_id could be userID or userCustomerID I am not sure which in your case, you decide.

How to hide siblings elements

How would I hide rest of the categories when I click on one, and if I click again rest of the categories would appear again.
<?php if($slide1_row_cnt > 0){ ?>
<div class="item active">
<h4>Groups</h4>
<?php while ($row = mysqli_fetch_assoc($slide1_result)) { ?>
<div class="row">
<div class="col-xs-2">
<p class="groups-list"><button type="button" class="btn btn-primary groups-button" rel="/tasks/stock/stock-category-list.php?filter=<?php echo $row['id_stc']; ?>"><?php echo $row['description_stc']; ?></button></p>
</div>
</div>
<?php } ?>
</div>
<!-- /Slide1 -->
Javascript:
$('.groups-button').click(function() {
$(this).parent('p').siblings().toggle();
});
Thanks
Based on your code shared
<?php while ($row = mysqli_fetch_assoc($slide1_result)) {
You are showing a list of rows, so you should hide the rows
$(this).closest('.row').siblings().toggle();

Get multiple checkbox values in Yii

I have a page in which a user is able to select his desired category and get a listing of organizations. As for now, I've managed to get data from one selected category.
My issue now is getting multiple selected categories and retrieve data from multiple ids.
List of categories:
<div class="col-md-4 sidebar well col-md-push-8">
<div class="sidebar__block">
<div class="sidebar__inner">
<h4 class="h4">Filter by category</h4>
<?php foreach ($categories as $c): ?>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" name="category[]" id="<?php echo $c->id;?>" value="<?php echo $c->id;?>" class="styled" <?php if($c->id==$_GET['category']){ echo 'checked="checked"'; } ?>>
<label for="<?php echo $c->title; ?>"><?php echo $c->title;?></label>
</div>
</div>
<?php endforeach ?>
<div class="form-group">
<button type="submit" class="btn btn-sd btn-sd-green full-width filter_button" name="subscribe">Filter <i class="icon-right-small"></i></button>
</div>
</div>
</div>
</div>
List of data(organizations according to category selected):
<div class="col-md-8 col-md-pull-4">
<!--start show category with title-->
<div class="lgi__block lgi__block-2" id="appnendGridId">
<!--start show single category with title-->
<?php if(!empty($enterprises)): ?>
<?php foreach ($enterprises as $e): ?>
<div class="lgi__item category1">
<a class="lgi__item-inner" target="_blank" href="<?php echo $this->createUrl('frontend/enterprise', array('id' => $e->id)) ?>">
<div class="lgi__block-img">
<h5 class="lgi__label"><?php if($e->isIdeaEnterpriseActiveAccreditedMembership()): ?><?php echo $e->renderIdeaEnterpriseMembership('text')?><?php endif; ?></h5>
<img class="img-responsive-full lgi__img wp-post-image" src="<?php echo $e['imageLogoUrl']; ?>" alt="">
<div class="overlay"></div>
</div>
<div class="lgi__title stripe">
<h4><?php echo $e['title']; ?></h4>
<p><?php echo ysUtil::truncate($e['text_oneliner'], 85) ?></p>
</div>
</a>
</div>
<?php endforeach ?>
<?php else: ?>
<?php echo Notice::inline('Enterprises not found in this category or keyword') ?>
<?php endif; ?>
<!--end show single category with title-->
</div>
<!--end show category with title-->
<div class="row load_more_div">
<div class="col-sm-12 text-center">
<button type="button" class="btn btn-sd btn-sd-green full-width load-more-posts collapse please_wait_btn_class">
<h4 style="margin-top: 7px; color: #fff;">Loading...</h4>
</button>
<button type="button" class="btn btn-sd btn-sd-green full-width load-more-posts load_more_btn_class">
Load More <i class="icon-arr-down"></i>
</button>
</div>
</div>
</div>
JS :
$(document).on('click','.filter_button',function(e){
e.preventDefault();
var category = [];
$.each($("input[name='category[]']:checked"), function(){
window.location.replace('/idea/frontend/explore/category/'+$(this).val());
});
});
Appreciate if anyone could help me in this matter.

How can i create a new set of columns to my code below instead of row?

I am trying to create a information site for my coworkers where they can add all the info they have so they don't need to write it down. The variable $cam_loc displays the location of certain equipment. When i use the code below instead of using one panel title per location it duplicates the location if there is more than 1 equipment in that place. I would like to make a conditional that verifies if the location is duplicated and if so instead of adding another panel-title it should add another column with the second pair of information in that location.
This is the code:
<?php
$cam = $db->prepare('select * from camere');
$cam->execute();
while ($cams = $cam->fetch(PDO::FETCH_OBJ)) {?>
<ul class="list" style="list-style: none;">
<div class="panel panel-primary">
<div class="panel-heading">
<li><h3 class="panel-title"><?php $cam_loc = $cams->locatie; ?><?php echo $cam_loc;?></h3> </li>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-2" align="center">
<div class="list-group">
<a class="list-group-item">Model: <strong><?php echo $cams->model; ?></strong></a>
<a class="list-group-item">Ip Intern: <strong><?php echo $cams->ip_int; ?></strong></a>
<a class="list-group-item">Ip Extern: <strong><?php echo $cams->ip_ext; ?></strong></a>
<a class="list-group-item">Port: <strong><?php echo $cams->port; ?></strong></a>
<a class="list-group-item">User: <strong><?php echo $cams->user; ?></strong></a>
<a class="list-group-item">Pass: <strong><?php echo $cams->pass; ?></strong></a>
</div>
</div>
</div>
</div>
</div>
</ul>
<?php } ?>
Firstly you'd need to sort your results by title in your SQL statement which will group them together, then use an if statement to work out if the current record has the same title as the previous one.
<?php
$cam = $db->prepare('select * from camere');
$cam->execute();
$heading = "";
while ($cams = $cam->fetch(PDO::FETCH_OBJ)) {?>
<ul class="list" style="list-style: none;">
<div class="panel panel-primary">
<?php $cam_loc = $cams->locatie;
if ($heading != $cam_loc) { ?>
<div class="panel-heading">
<li><h3 class="panel-title"><?php echo $cam_loc; ?></h3> </li>
</div>
<?php }
//Update $heading ready for the next row.
$heading = $cam_loc;
} ?>
<div class="panel-body">
<div class="row">
<div class="col-md-2" align="center">
<div class="list-group">
<a class="list-group-item">Model: <strong><?php echo $cams->model; ?></strong></a>
<a class="list-group-item">Ip Intern: <strong><?php echo $cams->ip_int; ?></strong></a>
<a class="list-group-item">Ip Extern: <strong><?php echo $cams->ip_ext; ?></strong></a>
<a class="list-group-item">Port: <strong><?php echo $cams->port; ?></strong></a>
<a class="list-group-item">User: <strong><?php echo $cams->user; ?></strong></a>
<a class="list-group-item">Pass: <strong><?php echo $cams->pass; ?></strong></a>
</div>
</div>
</div>
</div>
</div>
</ul>
<?php } ?>
You may have to move some of your HTML tags around a bit within those new code lines to give you the desired layout you require but as it is above you won't get a new heading for every record.

how to post data from method of conroller in opencart2.x this example?

i want to create new method in class ControllerCatalogMproduct in opencart2.x
but i dont know do send data from mproduct_form.tpl when click save button to controller .
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-mproduct" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<i class="fa fa-reply"></i></div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
</div>
</div>
I have come to the question how when click the button with type submit without javascript and jquery,send post to controller and save in db!!!
when click or edit button in main page and update url to example:
http://www.example.com/admin/index.php?route=catalog/mproduct/edit&token=N3bmdZW8C&productid=67
whats mean $("form[id*='form-']").submit();?

Categories