How can I center image gallery within my div? - image

I am trying to center a PHP generated image gallery horizontally on the page. It seems I have tried everything but nothing works! Here is a link to the page: http://rabbittattoo.com/?gallery=gallery
Here is the html that for the gallery:
<!-- Begin content -->
<div id="content_wrapper"><div class="inner">
<!-- Begin main content -->
<div id="gallery_wrapper" class="inner_wrapper portfolio"><div class="standard_wrapper small"><br class="clear"></br><br></br>
<!-- Begin portfolio content -->
<div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth last" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><br class="clear"></br><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth last" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><br class="clear"></br><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div></div>
<!-- End main content -->
And the associated CSS:
#content_wrapper .inner .inner_wrapper.portfolio {
padding: 10px 0px 0px;
position: relative;
left: -10px;
}
#content_wrapper .inner .inner_wrapper {
margin-top: 28px;
}
#content_wrapper .inner .inner_wrapper {
width: 91%;
margin-left: 5.5%;
padding: 10px 0px 25px;
background: none repeat scroll 0% 0% transparent;
margin-top: 30px;
}
#gallery_wrapper {
width: 100%;
margin: 0px auto;
}
And the PHP:
$pp_gallery_style = get_option('pp_gallery_style');
if($pp_gallery_style == 'f')
{
include_once(TEMPLATEPATH.'/gallery-f.php');
exit;
}
if(!isset($hide_header) OR !$hide_header)
{
get_header();
}
$caption_class = "page_caption";
$portfolio_sets_query = '';
$custom_title = '';
if(!empty($term))
{
$portfolio_sets_query.= $term;
$obj_term = get_term_by('slug', $term, 'photos_galleries');
$custom_title = $obj_term->name;
}
else
{
$custom_title = get_the_title();
}
/**
* Get Current page object
**/
$page = get_page($post->ID);
/**
* Get current page id
**/
if(!isset($current_page_id) && isset($page->ID))
{
$current_page_id = $page->ID;
}
if(!isset($hide_header) OR !$hide_header)
{
?>
<div class="wrapper_shadow"></div>
<div class="page_caption">
<div class="caption_inner">
<div class="caption_header">
<h1 class="cufon"><?php echo the_title(); ?></h1>
</div>
</div>
</div>
</div>
<!-- Begin content -->
<div id="content_wrapper">
<div class="inner">
<!-- Begin main content -->
<div id="gallery_wrapper" class="inner_wrapper portfolio">
<div class="standard_wrapper small">
<br class="clear"/><br/>
<?php
}
else
{
echo '<br class="clear"/>';
}
?>
<?php echo do_shortcode(html_entity_decode($page->post_content)); ?>
<!-- Begin portfolio content -->
<?php
$menu_sets_query = '';
$portfolio_items = 0;
$portfolio_sort = get_option('pp_gallery_sort');
if(empty($portfolio_sort))
{
$portfolio_sort = 'DESC';
}
$args = array(
'post_type' => 'attachment',
'numberposts' => $portfolio_items,
'post_status' => null,
'post_parent' => $post->ID,
'order' => $portfolio_sort,
'orderby' => 'date',
);
$all_photo_arr = get_posts( $args );
if(isset($all_photo_arr) && !empty($all_photo_arr))
{
?>
<?php
foreach($all_photo_arr as $key => $portfolio_item)
{
$image_url = '';
if(!empty($portfolio_item->guid))
{
$image_id = $portfolio_item->ID;
$image_url[0] = $portfolio_item->guid;
}
$last_class = '';
$line_break = '';
if(($key+1) % 4 == 0)
{
$last_class = ' last';
if(isset($page_photo_arr[$key+1]))
{
$line_break = '<br class="clear"/><br/>';
}
else
{
$line_break = '<br class="clear"/>';
}
}
?>
<div class="one_fourth<?php echo $last_class?>" style="margin-right:24px;margin-bottom:24px;margin-top:-20px">
<a title="<?php echo $portfolio_item->post_title?>" href="<?php echo $image_url[0]?>" class="one_fourth_img" rel="gallery" href="<?php echo $image_url[0]?>">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/timthumb.php?src=<?php echo $image_url[0]?>&h=370&w=350&zc=1" alt=""/>
</a>
</div>
<?php
echo $line_break;
}
//End foreach loop
?>
<?php
}
//End if have portfolio items
?>
</div>
<!-- End main content -->
<br class="clear"/><br/>
</div>
<?php
if(!isset($hide_header) OR !$hide_header)
{
?>
</div>
<!-- End content -->
<?php get_footer(); ?>
<?php
}
?>
I have tried centering by adjusting the margins but is had no effect. Can anyone tell me what I am doing wrong? Thank you in advance for your help!

Related

how to dynamically change owl carousel image from MySQL database with information

I was searching online all day today and could not find any solution for adding a dynamic image to owl carousel from MySQL database with information. If anyone can help?
I have done something like the following but I am getting only one slide, Like bootstrap, it is not showing all the images and table information from the database. If I loop it gives me all the tables on the same page.
<link rel="stylesheet" type="text/css" href="http://www.24limousine.com/wp-content/themes/24Limousine/assets/css/owl.carousel.min.css">
<?php
$connect = mysqli_connect("localhost", "root", "", "testing");
function make_query($connect)
{
$query = "SELECT * FROM banner ORDER BY banner_id ASC";
$result = mysqli_query($connect, $query);
return $result;
}
function make_slide_indicators($connect)
{
$output = '';
$count = 0;
$result = make_query($connect);
while($row = mysqli_fetch_array($result))
{
if($count == 0)
{
$output .= '
<li data-target="#dynamic_slide_show" data-slide-to="'.$count.'" class="active"></li>
';
}
else
{
$output .= '
<li data-target="#dynamic_slide_show" data-slide-to="'.$count.'"></li>
';
}
$count = $count + 1;
}
return $output;
}
return $output;
}
function make_slides($connect)
{
$output = '';
$count = 0;
$result = make_query($connect);
while($row = mysqli_fetch_array($result))
{
if($count == 0)
{
$output .= '<div class="item active">';
}
else
{
$output .= '<div class="item">';
}
$output .= '
<img src="banner/'.$row["banner_image"].'" alt="'.$row["banner_title"].'" />
<div class="carousel-caption">
<h3>'.$row["banner_title"].'</h3>
</div>
</div>
';
$count = $count + 2;
}
return $output;
}
?>
<div class="cover-wrapper">
<div id="client-logos" class="owl-carousel text-center">
<div class="item">
<div class="client-inners">
<?php echo make_slides($connect); ?>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.24limousine.com/wp-content/themes/24Limousine/assets/js/owl.carousel.min.js"></script>
<script>
$(document).ready(function() {
$('#client-logos').owlCarousel({
// loop:true,
margin:15,
nav:true,
responsive:{
0:{
items:2
},
600:{
items:4
},
1000:{
items:6
}
},
navText: ["<img src='http://pixsector.com/cache/a8009c95/av8a49a4f81c3318dc69d.png'/>","<img src='http://pixsector.com/cache/81183b13/avcc910c4ee5888b858fe.png'/>"]
});

Codeigniter Repotrs page problem with dates

I am developing a project using Codeigniter framework and in the reports page i need to have a form that has datatables structure so i can generate reports by day,month and year. but i dont know how to use datatables.
i have tried to add code like for example where it was written Y-m i added d-m-y but it doesn't work
Reports Controller:
defined('BASEPATH') OR exit('No direct script access allowed');
class Reports extends Admin_Controller
{
public function __construct()
{
parent::__construct();
$this->data['page_title'] = 'Stores';
$this->load->model('model_reports');
}
/*
* It redirects to the report page
* and based on the year, all the orders data are fetch from the database.
*/
public function index()
{
if(!in_array('viewReports', $this->permission)) {
redirect('dashboard', 'refresh');
}
$today_year = date('Y');
if($this->input->post('select_year')) {
$today_year = $this->input->post('select_year');
}
$parking_data = $this->model_reports->getOrderData($today_year);
$this->data['report_years'] = $this->model_reports->getOrderYear();
$final_parking_data = array();
foreach ($parking_data as $k => $v) {
if(count($v) > 1) {
$total_amount_earned = array();
foreach ($v as $k2 => $v2) {
if($v2) {
$total_amount_earned[] = $v2['net_amount'];
}
}
$final_parking_data[$k] = array_sum($total_amount_earned);
}
else {
$final_parking_data[$k] = 0;
}
}
$this->data['selected_year'] = $today_year;
$this->data['company_currency'] = $this->company_currency();
$this->data['results'] = $final_parking_data;
$this->render_template('reports/index', $this->data);
}
}
**Reports Model:**
<?php
class Model_reports extends CI_Model
{
public function __construct()
{
parent::__construct();
}
/*getting the total months*/
private function months()
{
return array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
}
/* getting the year of the orders */
public function getOrderYear()
{
$sql = "SELECT * FROM orders WHERE paid_status = ?";
$query = $this->db->query($sql, array(1));
$result = $query->result_array();
$return_data = array();
foreach ($result as $k => $v) {
$date = date('Y', $v['date_time']);
$return_data[] = $date;
}
$return_data = array_unique($return_data);
return $return_data;
}
// getting the order reports based on the year and moths
public function getOrderData($year)
{
if($year) {
$months = $this->months();
$sql = "SELECT * FROM orders WHERE paid_status = ?";
$query = $this->db->query($sql, array(1));
$result = $query->result_array();
$final_data = array();
foreach ($months as $month_k => $month_y) {
$get_mon_year = $year.'-'.$month_y;
$final_data[$get_mon_year][] = '';
foreach ($result as $k => $v) {
$month_year = date('Y-m', $v['date_time']);
if($get_mon_year == $month_year) {
$final_data[$get_mon_year][] = $v;
}
}
}
return $final_data;
}
}
}
**View index**
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Reports
</h1>
<ol class="breadcrumb">
<li><i class="fa fa-dashboard"></i> Home</li>
<li class="active">Reports</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-md-12 col-xs-12">
<form class="form-inline" action="<?php echo base_url('reports/') ?>" method="POST">
<div class="form-group">
<label for="date">Year</label>
<select class="form-control" name="select_year" id="select_year">
<?php foreach ($report_years as $key => $value): ?>
<option value="<?php echo $value ?>" <?php if($value == $selected_year) { echo "selected"; } ?>><?php echo $value; ?></option>
<?php endforeach ?>
</select>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<br /> <br />
<div class="col-md-12 col-xs-12">
<?php if($this->session->flashdata('success')): ?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<?php echo $this->session->flashdata('success'); ?>
</div>
<?php elseif($this->session->flashdata('error')): ?>
<div class="alert alert-error alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<?php echo $this->session->flashdata('error'); ?>
</div>
<?php endif; ?>
<div class="box">
<div class="box-header">
<h3 class="box-title">Total - Report</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="chart">
<canvas id="barChart" style="height:250px"></canvas>
</div>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
<div class="box">
<div class="box-header">
<h3 class="box-title">Total Paid Orders - Report Data</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="datatables" class="table table-bordered table-striped">
<thead>
<tr>
<th>Month - Year</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $k => $v): ?>
<tr>
<td><?php echo $k; ?></td>
<td><?php
echo $company_currency .' ' . $v;
//echo $v;
?></td>
</tr>
<?php endforeach ?>
</tbody>
<tbody>
<tr>
<th>Total Amount</th>
<th>
<?php //echo $company_currency . ' ' . array_sum($parking_data); ?>
<?php echo array_sum($results); ?>
</th>
</tr>
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- col-md-12 -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<script type="text/javascript">
$(document).ready(function() {
$("#reportNav").addClass('active');
});
var report_data = <?php echo '[' . implode(',', $results) . ']'; ?>;
$(function () {
/* ChartJS
* -------
* Here we will create a few charts using ChartJS
*/
var areaChartData = {
labels : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
datasets: [
{
label : 'Electronics',
fillColor : 'rgba(210, 214, 222, 1)',
strokeColor : 'rgba(210, 214, 222, 1)',
pointColor : 'rgba(210, 214, 222, 1)',
pointStrokeColor : '#c1c7d1',
pointHighlightFill : '#fff',
pointHighlightStroke: 'rgba(220,220,220,1)',
data : report_data
}
]
}
//-------------
//- BAR CHART -
//-------------
var barChartCanvas = $('#barChart').get(0).getContext('2d')
var barChart = new Chart(barChartCanvas)
var barChartData = areaChartData
barChartData.datasets[0].fillColor = '#00a65a';
barChartData.datasets[0].strokeColor = '#00a65a';
barChartData.datasets[0].pointColor = '#00a65a';
var barChartOptions = {
//Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
scaleBeginAtZero : true,
//Boolean - Whether grid lines are shown across the chart
scaleShowGridLines : true,
//String - Colour of the grid lines
scaleGridLineColor : 'rgba(0,0,0,.05)',
//Number - Width of the grid lines
scaleGridLineWidth : 1,
//Boolean - Whether to show horizontal lines (except X axis)
scaleShowHorizontalLines: true,
//Boolean - Whether to show vertical lines (except Y axis)
scaleShowVerticalLines : true,
//Boolean - If there is a stroke on each bar
barShowStroke : true,
//Number - Pixel width of the bar stroke
barStrokeWidth : 2,
//Number - Spacing between each of the X value sets
barValueSpacing : 5,
//Number - Spacing between data sets within X values
barDatasetSpacing : 1,
//String - A legend template
legendTemplate : '<ul class="<%=name.toLowerCase()%>-legend"><% for (var i=0; i<datasets.length; i++){%><li><span style="background-color:<%=datasets[i].fillColor%>"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>',
//Boolean - whether to make the chart responsive
responsive : true,
maintainAspectRatio : true
}
barChartOptions.datasetFill = false
barChart.Bar(barChartData, barChartOptions)
})
</script>

session destrioyed on add to cart in laravel

I am using laravel5. I need to add the product into cart. when i add a new product it is add into cart item as 1. but when refresh the page or move to next page my cart item count destroyed. Here i attach my coding. Please help me what is my mistake. i am new to laravel
Controller:
public function cart($request)
{
$quick=Mainpage::get_quick(5);
$logo = Mainpage::get_image();
$result_cart = Mainpage::get_add_to_cart_details();
$session_result = '';
// if(Session::get('cus_id'))
// {
// $navbar = View::make('layout.header');
// }
// else
// {
// $navbar = View::make('layout.header');
// }
return view('cart', ['logo' => $logo, 'quick' =>$quick,'session_result'=>$session_result,'result_cart'=>$result_cart]);
}
Model:
public static function get_add_to_cart_details()
{
$get_pro_dea = "";
if(isset($_SESSION['cart'])){
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['product_id'];
//$pname="Have to get";
$get_pro_dea[$pid] = DB::table('le_product')->where('product_id',$pid)->get();
}
}
else
{
$get_pro_dea[0] = array();
}
return $get_pro_dea;
}
View:(header.blade.php):
<div class="col-sm-4" style="margin-top:17px">
<div class="cart box_1 pull-right">
<a href="<?php echo url('cart'); ?>">
<?php if(isset($_SESSION['cart']))
{
$item_count_header1 = count($_SESSION['cart']);
}
else {
$item_count_header1 = 0;
}
$item_count_header = $item_count_header1;
if($item_count_header != 0)
{
?>
<img src='<?php echo url(); ?>/assets/images/shopping-cart.png' alt=''><span style='color:black;
'> ( <?php echo $item_count_header; ?> Items) </span>
<?php
}
else
{ ?>
<img src="<?php echo url(); ?>/assets/images/shopping-cart.png" alt=""><span style="color:black;"> (card empty)</span>
<?php }
?>
</strong>
</a>
</div>
</div>
</div>
<?php } ?>
</div>

keep all selected values after submit

I'm stuck with this script I'm using:
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="includes/css/style.css" type="text/css" rel="stylesheet" />
<link href="includes/css/wt-gallery.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="includes/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="includes/js/configuratie.js"></script>
<script type="text/javascript" src="includes/js/jquery.wt-gallery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#drop_1').change(function(){
$('#wait_1').show();
$('#result_1').hide();
$.get("func.php", {
func: "drop_1",
drop_var: $('#drop_1').val()
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
});
return false;
});
$('#wait_2').hide();
$('#drop_2').change(function(){
$('#wait_2').show();
$('#result_2').hide();
$.get("func.php", {
func: "drop_2",
drop_var: $('#drop_2').val()
}, function(response){
$('#result_2').fadeOut();
setTimeout("finishAjax2('result_2', '"+escape(response)+"')", 400);
});
return false;
});
$('#wait_3').hide();
$('#drop_3').change(function(){
$('#wait_3').show();
$('#result_3').hide();
$.get("func.php", {
func: "drop_3",
drop_var: $('#drop_3').val()
}, function(response){
$('#result_3').fadeOut();
setTimeout("finishAjax3('result_3', '"+escape(response)+"')", 400);
});
return false;
});
});
function finishAjax(id, response) {
$('#wait_1').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
function finishAjax2(id, response) {
$('#wait_2').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
function finishAjax3(id, response) {
$('#wait_3').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
function finishAjax_tier_three(id, response) {
$('#wait_2').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
function finishAjax_tier_four(id, response) {
$('#wait_3').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
function finishAjax_tier_five(id, response) {
$('#wait_4').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
</head>
<?php
$website = "it";
// configuratie file en db connect
include "includes/inc/config.inc.php";
include('db.php');
include_once "class/slider.class.php";
include('func.php');
$slideralbum = new slideralbum($dbo);
$sliders = $slideralbum->getSliderItems($website);
?>
<body>
<p>
<form name="product" action="" method="post">
<select name="drop_1" id="drop_1">
<option value="" selected="selected" disabled="disabled">Selecteer Merk</option>
<?php getTierOne(); ?>
</select>
<span id="wait_1" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_1" style="display: none;"></span>
<span id="wait_2" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_2" style="display: none;"></span>
<span id="wait_3" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_3" style="display: none;"></span>
<span id="wait_4" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_4" style="display: none;"></span>
<INPUT TYPE="button" VALUE="Refresh" onclick='location.reload()'>
</form>
</p>
<p>
<?php if(isset($_POST['submit'])){
$drop = $_POST['drop_1'];
$drop_2 = $_POST['drop_2'];
$drop_3 = $_POST['drop_3'];
$drop_4 = $_POST['drop_4'];
$drop_5 = $_POST['drop_5'];
?>
<table border="1" bordercolor="#B5B5B5" style="background-color:#FFFFFF" width="250" cellpadding="3" cellspacing="3">
<tr>
<td>Merk:</td>
<td><?php echo $drop;?></td>
</tr>
<tr>
<td>Model:</td>
<td><?php echo $drop_2;?></td>
</tr>
<tr>
<td>Bouwjaar:</td>
<td><?php echo $drop_3;?></td>
</tr>
<tr>
<td>Kleur:</td>
<td><?php echo $drop_4;?></td>
</tr>
</table>
<?php
}
?>
<div id="banner-block"> <!-- Begin of Slideshow -->
<div class="container">
<div class="wt-gallery" style="width:920px; height:375px;">
<div class="main-screen">
<?php if(isset($_POST['submit'])){
$drop = $_POST['drop_1'];
$drop_2 = $_POST['drop_2'];
$drop_3 = $_POST['drop_3'];
$drop_4 = $_POST['drop_4'];
$drop_5 = $_POST['drop_5'];
?>
<img src="images/<?php echo $drop_5;?>" alt="<?php echo $drop_5;?>" width="920" height="360"/>
<?php
}
?>
<noscript>
<!-- placeholder image when javascript is off -->
<img src="../images/triworks_abstract27.jpg" alt=""/>
</noscript>
</div>
<div class="cpanel">
<div class="thumbs-back"></div>
<div class="thumbnails">
<ul>
<?php $sliders = $slideralbum->getSliderItems($website, NULL);
foreach($sliders as $slider){
?>
<li effect="none">
<div>
<a href="<?php echo $slider->slider_img; ?>" height="360" width="720" alt="<?php echo $slider->slider_img; ?>" />
<img src="<?php echo $slider->slider_tmb; ?>" height="70" width="125" alt="<?php echo $slider->slider_tmb; ?>" />
</a>
</div>
<div class="data">
</div>
</li>
<?php
}
?>
</ul>
</div>
<div class="thumbs-fwd"></div>
</div>
</div>
</div>
</div>
</body>
</html>
func.php
<?php
//**************************************
// Page load dropdown results //
//**************************************
function getTierOne()
{
$result = mysql_query("SELECT DISTINCT make FROM vehicles ORDER BY make ASC")
or die(mysql_error());
while($tier = mysql_fetch_array( $result ))
{
?>
<option value="<?php echo $tier['make'];?>"<?php echo (isset($_POST['drop_1']) && $_POST['drop_1'] == $tier['make']) ? ' selected="selected"' : '' ; ?>><?php echo $tier['make'];?></option>
<?php
}
}
//**************************************
// First selection results //
//**************************************
if (isset($_GET['func'])&& $_GET['func'] == "drop_1" ) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
include_once('db.php');
$result = mysql_query("SELECT DISTINCT model FROM vehicles WHERE make='$drop_var' ORDER BY model")
or die(mysql_error());
echo '<select name="drop_2" id="drop_2">
<option value=" " disabled="disabled" selected="selected">Selecteer Model</option>';
while($drop_2 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_2['model'].'">'.$drop_2['model'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_2').hide();
$('#drop_2').change(function(){
$('#wait_2').show();
$('#result_2').hide();
$.get(\"func.php\", {
func: \"drop_2\",
drop_var: $('#drop_1').val(),
drop_var2: $('#drop_2').val()
}, function(response){
$('#result_2').fadeOut();
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
//**************************************
// Second selection results //
//**************************************
if (isset($_GET['func'])&& $_GET['func'] == "drop_2" ) {
drop_2($_GET['drop_var'], $_GET['drop_var2']);
}
function drop_2($drop_var, $drop_var2)
{
include_once('db.php');
$result = mysql_query("SELECT DISTINCT year FROM vehicles WHERE make='$drop_var' AND model='$drop_var2'")
or die(mysql_error());
echo '<select name="drop_3" id="drop_3">
<option value=" " disabled="disabled" selected="selected">Selecteer Jaar</option>';
while($drop_3 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_3['year'].'">'.$drop_3['year'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_3').hide();
$('#drop_3').change(function(){
$('#wait_3').show();
$('#result_3').hide();
$.get(\"func.php\", {
func: \"drop_3\",
drop_var: $('#drop_1').val(),
drop_var2: $('#drop_2').val(),
drop_var3: $('#drop_3').val()
}, function(response){
$('#result_3').fadeOut();
setTimeout(\"finishAjax_tier_four('result_3', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
//**************************************
// Third selection results //
//**************************************
if (isset($_GET['func'])&& $_GET['func'] == "drop_3" ) {
drop_3($_GET['drop_var'], $_GET['drop_var2'], $_GET['drop_var3']);
}
function drop_3($drop_var, $drop_var2, $drop_var3)
{
include_once('db.php');
$result = mysql_query("SELECT DISTINCT color FROM vehicles WHERE make='$drop_var' AND model='$drop_var2' AND year='$drop_var3'")
or die(mysql_error());
echo '<select name="drop_4" id="drop_4">
<option value=" " disabled="disabled" selected="selected">Selecteer Kleur</option>';
while($drop_4 = mysql_fetch_array( $result ))
{
if ($drop_4['color'] != "") {
echo '<option value="'.$drop_4['color'].'">'.$drop_4['color'].'</option>';
}
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_4').hide();
$('#drop_4').change(function(){
$('#wait_4').show();
$('#result_4').hide();
$.get(\"func.php\", {
func: \"drop_4\",
drop_var: $('#drop_1').val(),
drop_var2: $('#drop_2').val(),
drop_var3: $('#drop_3').val(),
drop_var4: $('#drop_4').val()
}, function(response){
$('#result_4').fadeOut();
setTimeout(\"finishAjax_tier_five('result_4', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
//**************************************
// Fourth selection results //
//**************************************
if(isset($_GET['func'])&& $_GET['func'] == "drop_4" ) {
drop_4($_GET['drop_var'], $_GET['drop_var2'], $_GET['drop_var3'], $_GET['drop_var4']);
}
function drop_4($drop_var, $drop_var2, $drop_var3, $drop_var4)
{
include_once('db.php');
$result = mysql_query("SELECT * FROM vehicles WHERE make='$drop_var' AND model='$drop_var2' AND year='$drop_var3' AND color='$drop_var4'")
or die(mysql_error());
while($drop_5 = mysql_fetch_array( $result ))
{
if ($drop_5['img'] != "") {
echo '<input type="checkbox" name="drop_5" id="drop_5" style="display:none;" checked value="'.$drop_5['img'].'"/>';
}
}
echo '<input type="submit" name="submit" value="Submit" />';
}
?>
After I selected all my dropdown items and press submit it is working good but all the selected values are gone...
If you want to change color you have to go to the whole dropdown list again. Is it possible to keep all the selected values after submit?
Thanks in advance
Kind Regards
Joep
You are using GET requests to display each dropdown list in turn, and then using a POST request to submit your completed form. You should make sure that all the dropdowns are displayed after the POST request.
In index.php, I think you could try something like that :
<span id="result_1" style="display: none;">
<?php
if (isset($_POST['submit']) {
drop_1($_POST['drop_1']);
}
?>
</span>
...
<span id="result_2" style="display: none;">
<?php
if (isset($_POST['submit']) {
drop_2($_POST['drop_1'], $_POST['drop_2']);
}
?>
</span>
...
<span id="result_3" style="display: none;">
<?php
if (isset($_POST['submit']) {
drop_3($_POST['drop_1'], $_POST['drop_2'], $_POST['drop_3']);
}
?>
</span>
etc...
Anyway, the idea is to reuse the functions that build your dropdowns, based on the values in the $_POST.

Magento 1.6.2 Previous Next buttons for moving from one product to another in a sub category

i want to create a previous next buttons for moving from one product to another in a specific category.
i was using this code in view.phtml, but now its giving undefined variable error for $search_parameter.
<?php // Previous and Next product links in product page
$_product = $this->getProduct();
if(!$_product->getCategoryIds())
return; // Don't show Previous and Next if product is not in any category
$cat_ids = $_product->getCategoryIds(); // get all categories where the product is located
$cat = Mage::getModel('catalog/category')->load( $cat_ids[0] ); // load first category, you should enhance this, it works for me
$order = Mage::getStoreConfig('catalog/frontend/default_sort_by');
$direction = 'asc'; // asc or desc
$category_products = $cat->getProductCollection()->addAttributeToSort($order, $direction);
$category_products->addAttributeToFilter('status',1); // 1 or 2
$category_products->addAttributeToFilter('visibility',4); // 1.2.3.4
$cat_prod_ids = $category_products->getAllIds(); // get all products from the category
$_product_id = $_product->getId();
$_pos = array_search($_product_id, $cat_prod_ids); // get position of current product
$_next_pos = $_pos+1;
$_prev_pos = $_pos-1;
// get the next product url
if( isset($cat_prod_ids[$_next_pos]) ) {
$_next_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_next_pos] );
} else {
$_next_prod = Mage::getModel('catalog/product')->load( reset($cat_prod_ids) );
}
// get the previous product url
if( isset($cat_prod_ids[$_prev_pos]) ) {
$_prev_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_prev_pos] );
} else {
$_prev_prod = Mage::getModel('catalog/product')->load( end($cat_prod_ids) );
}
?>
<div class="clear"></div>
<!--PREVIOUS BUTTON NEXT BUTTON STARTS-->
<div class="previousNext">
<?php if($_prev_prod != NULL): ?>
<span style="margin-right: 270px;"><?php echo $this->__('<< PREVIOUS') ?></span>
<?php endif; ?>
<?php if($_next_prod != NULL): ?>
<span style="margin-left: 270px;"><?php echo $this->__('NEXT >>') ?></span>
<?php endif; ?>
</div>
<!--PREVIOUS BUTTON NEXT BUTTON ENDS-->
<div class="clear"></div>
hey finally got the above code to work on my website..
Following are the steps followed:
STEP1: While adding products MAKE SURE each product is added to ONE CATEGORY only. A product in more than one category, this code does not work. IN other words, if you are adding a product to say Cat1 > Subcat1 > subsubcat2, make sure you only add it to subsubcat2. THan you will be able to move next previous within that sub sub cat.
STEP2: Open view.phtml and add the following code:
<?php // Previous and Next product links in product page
$_product = $this->getProduct();
if(!$_product->getCategoryIds())
return; // Don't show Previous and Next if product is not in any category
$cat_ids = $_product->getCategoryIds(); // get all categories where the product is located
$cat = Mage::getModel('catalog/category')->load( $cat_ids[0] ); // load first category, you should enhance this, it works for me
$order = Mage::getStoreConfig('catalog/frontend/default_sort_by');
$direction = 'desc'; // asc or desc
$category_products = $cat->getProductCollection()->addAttributeToSort($order, $direction);
$category_products->addAttributeToFilter('status',1); // 1 or 2
$category_products->addAttributeToFilter('visibility',4); // 1.2.3.4
$cat_prod_ids = $category_products->getAllIds(); // get all products from the category
$_product_id = $_product->getId();
$_pos = array_search($_product_id, $cat_prod_ids); // get position of current product
$_next_pos = $_pos+1;
$_prev_pos = $_pos-1;
// get the next product url
if( isset($cat_prod_ids[$_next_pos]) ) {
$_next_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_next_pos] );
} else {
$_next_prod = Mage::getModel('catalog/product')->load( reset($cat_prod_ids) );
}
// get the previous product url
if( isset($cat_prod_ids[$_prev_pos]) ) {
$_prev_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_prev_pos] );
} else {
$_prev_prod = Mage::getModel('catalog/product')->load( end($cat_prod_ids) );
}
?>
STEP3: Add the PREVIOS and NEXT buttons code
<!--PREVIOUS BUTTON NEXT BUTTON STARTS-->
<div class="previousNext">
<?php if($_prev_prod != NULL): ?>
<span style="margin-right: 270px;"><?php echo $this->__('<< PREVIOUS') ?></span>
<?php endif; ?>
<?php if($_next_prod != NULL): ?>
<span style="margin-left: 270px;"><?php echo $this->__('NEXT >>') ?></span>
<?php endif; ?>
</div>
<!--PREVIOUS BUTTON NEXT BUTTON ENDS-->
STEP4: Add css style to the links
<style>
.previousNext {width: 100%; height: 20px; text-align: right; }
.previousNext a:link {font-size: 12px; color:#ffffff; font-weight: bold; text-decoration: none}
.previousNext a:visited {font-size: 12px; color:#ffffff; font-weight: bold; text-decoration: none}
.previousNext a:hover {font-size: 12px; color:#ff9900; font-weight: bold; text-decoration: underline}
.previousNext a:active {font-size: 12px; color:#ffffff; font-weight: bold; text-decoration: none}
</style>
Position the previous next buttons ideally inside the product-essential div (default template)
And your next or previos project is ready work...
Hope this helps...

Resources