I use codeigniter pagination also here i use ajax to search so that the paging does not works. While click the paging link the full page is get reloaded .Actually i am not familiar with ajax so i dont know how this problem can be solved.Any help is appreciated.
Controller
public function chrgs_ajs_result()
{
$type = $this->input->post('catg');
$sdate = $this->input->post('start_date');
$edate = $this->input->post('end_date');
$result['error'] = "";
$result['res'] = "";
$result['res'] = $this->chrgs_edit_report_model->get_edit_amount($type,$sdate,$edate);
$config['base_url'] = base_url() . 'index.php/payment_edit/chrgs_ajs_result';
$config['total_rows'] = count($result['res']);
$config['per_page'] = 15;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$result['res'] = $this->chrgs_edit_report_model->get_edit_amount($type,$sdate,$edate,$config["per_page"], $page);
$result["links"] = $this->pagination->create_links();
//$result['res'] = $this->chrgs_edit_report_model->get_edit_amount($type,$sdate,$edate);
// echo "<pre>";
// print_r($result['res']);
if (!empty($result['res']))
{
$this->load->view('edit_charg_ajax_result',$result);
}
else
{
echo "No Result Found";
}
}
Ajax Result page
<table border="1" class="mainTable" cellpadding="0" cellspacing="0">
<tr> <?php if (isset($links)) { echo $links; } ?> </tr>
<tr style="background-color:#F2FAFF;color:#660">
<td width="3%">Sl No</td>
<td width="8%">Track Number</td>
<td width="8%">Old <?php echo $type; ?></td>
<td width="8%">New <?php echo $type; ?></td>
<td width="30%">Reason</td>
<td width="10%">Date</td>
<td width="10%">Requested By</td>
<td width="10%">Approved By</td>
<td width="10%">Approved IP</td>
</tr>
<?php
$i = 1;
foreach ($res as $value)
{
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $value['track_no']; ?></td>
<td><?php echo $value['old_value']; ?></td>
<td><?php echo $value['new_value']; ?></td>
<td><?php echo $value['reason']; ?></td>
<td><?php echo $value['added_on']; ?></td>
<td><?php echo $value['requested_by']; ?></td>
<td><?php echo $value['approved_by']; ?></td>
<td><?php echo $value['ip']; ?></td>
</tr>
<?php
$i++;
} ?>
Main Result page
<section>
<div class="content">
<div class="row">
<div class="col-md-12" style="margin-left: 2%;">
<div class="box">
<form class="form-horizontal" id="form">
<fieldset>
<div class="box-body">
<div class="col-md-12 row div1">
<div class="form-group col-md-4" style="margin-left: 80px;">
<label style="margin-top: 20px;"><b>Types:</b></label>
<div class="input-group" id="error">
<select class="form-control" id="catg" name="catg" style="width: 134%; border-radius: 5px;">
<option value="">--Select--</option>
<option value="charges">Charges</option>
<option value="delivery_at">Delivery_at</option>
<option value="doc_country">Doc_country</option>
<option value="doctype">Doctype</option>
<option value="mfa">Mfa</option>
<option value="package">Package</option>
<option value="sub_package">Sub_package</option>
</select>
</div>
</div>
<div class="form-group col-md-3" >
<label class="lmarg"><b>Start Date:</b></label>
<div class="input-group">
<div class="input-group-addon"> <i class="fa fa-calendar"></i> </div>
<input type="text" name="start_date" id="start_date" class="form-control datepicker">
</div>
</div>
<div class="form-group col-md-3" style="margin-left: 2px;">
<label class="lmarg"><b>End Date:</b></label>
<div class="input-group">
<div class="input-group-addon"> <i class="fa fa-calendar"></i> </div>
<input type="text" name="end_date" id="end_date" class="form-control datepicker">
</div>
</div>
<div class="form-group">
<label label class="lmarg" style="visibility: hidden;">search</label>
<div class="col-md-1 input-group">
<input type="button" class="btn pull-right" id="search_charge_edit" value="search">
</div>
</div>
</div>
</div>
</fieldset>
</form>
<div style="margin-top: 3%;margin-right: 1%;">
<div id="result" ></div>
</div></div>
</div>
</div>
</div>
$("#search_charge_edit").on("click",function(){
var controller_function = "<?php echo base_url();?>index.php/payment_edit/chrgs_ajs_result";
var post_data = $("#form").serialize();
$.ajax({
type:"post",
url:controller_function,
data:post_data,
success:function(data)
{
//alert(data);
//$('#form').trigger("reset");
$('#result').html(data);
}
});
});
Related
how to insert select option value in database using checkbox?When I click checkbox and click enroll button ,select option doesn't inserting selected value.I have 3 options(Regular,Retake,Recourse) in "examtype" table but when I choose more than one subject select option not working perfectly. Here is my code...
here is my select option image
<?php
if (isset($_POST['enroll']))
{
if (!empty($_POST['chk1']))
{
if (isset($_POST['et']))
{
$roll_no = $_SESSION['roll_no'];
//$selectbox1 = $_POST['et'];
foreach($_POST['chk1'] as $checkbox1)
{
foreach($_POST['et'] as $selectbox1)
//for($i=0;$i<sizeof($selectbox1);$i++)
$values = explode("|" , $checkbox1);
$values1= explode("|" , $selectbox1);
$course_id= $values[0];
$semester= $values[1];
$course_name= $values[2];
$selectbox1=$values1[0];
$sql="INSERT INTO pendingcourse(roll_no,course_id,semester,course_name,exam_type,status) VALUES('$roll_no','$course_id','$semester','$course_name','$selectbox1',0)";
$stmt = $connect->prepare($sql);
$stmt->execute();
$checkbox1='';
$selectbox1='';
}
header("location:coursetable.php");
}
}
}
?>
<form action="coursetable.php" method="post" enctype="multipart/form-data">
<div class="container mt-3" >
<div class="accordion mb-4" id="accordionExample" >
<div class="accordion-item" style="background-color: rgb(0, 225, 255);">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button collapsed fw-bold" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne" style="background: #AAFFA9;">
1st Semester
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" >
<div class="accordion-body">
<table class="table table-bordered border-primary text-center">
<thead>
<tr>
<th scope="col-1">Course Id</th>
<th scope="col-1">Semester</th>
<th scope="col-7">Course</th>
<th scope="col-1">Exam Type</th>
<th scope="col-1">Select</th>
<th scope="col-2">Result</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $connect->query("SELECT course_id,semester,course_name FROM coursetable Where semester = '1st' ");
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($rows as $row)
{
$course_id = $row['course_id'];
$semester = $row['semester'];
$course_name = $row['course_name'];
?>
<tr>
<td scope="row"> <?php echo $course_id?></td>
<td > <?php echo $semester ?></td>
<td ><?php echo $course_name ?></td>
<td>
<select name="et[]" class="form-select form-select-sm" aria-label=".form-select-sm example">
<?php
$stmt1 = $connect->query("SELECT * from examtype");
$rows1 = $stmt1->fetchAll(PDO::FETCH_ASSOC);
foreach($rows1 as $row1) {
?>
<option value="<?php echo $row1['exam_type']; ?>"><?php echo $row1['exam_type']; ?></option>
<?php
}
?>
</select>
</td>
<td>
<input type="checkbox" name="chk1[]" value="<?php echo $row['course_id']?>|<?php echo $row['semester']?>|<?php echo $row['course_name']?>|<?php echo $row1['exam_type']?>">
<label class="form-check-label" for="flexCheckDefault">
</label>
</td>
<td></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-2 col-xs-6 offset-md-5 mb-3">
<button type="submit" name="enroll" class="btn btn-warning mt-2">Enroll</button>
</div>
</div>
</div>
</form>
Place the input field inside a form and add
enctype="multipart/form-data"
<select name="et[]" class="form-select form-select-sm" aria-label=".form-select-sm example" multiple>
try this
add multiple in select
SOLVED:
<?php
if (isset($_POST['enroll']))
{
if (!empty($_POST['chk1']))
{
if (!empty($_POST['et']))
{
$roll_no = $_SESSION['roll_no'];
$selectbox1 = $_POST['et'];
$selectbox11=implode(',',array_filter($selectbox1));
$i=0;
foreach($_POST['chk1'] as $checkbox1)
{
$selectbox111 = array_diff(explode(",", $selectbox11),array(""));
$selectbox1111 = $selectbox111[$i];
$values = explode("|" , $checkbox1);
$course_id= $values[0];
$semester= $values[1];
$course_name= $values[2];
$sql="INSERT INTO pendingcourse(roll_no,course_id,semester,course_name,exam_type,status) VALUES('$roll_no','$course_id','$semester','$course_name','$selectbox1111',0)";
$stmt = $connect->prepare($sql);
$stmt->execute();
$checkbox1='';
$i++;
}
}
}
}
?>
I am developing a app (Online Vehicle Sales Management System), I inserted data in DB and display all record on single page, but I have a problem, I want select a single record by clicking on button and show it another page ...
Here is code:
<html>
<head>
<title>New Purchase</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<?php
session_start();
if (isset($_POST['logout'])) {
session_destroy();
header("location: ovsms.php");
}
?>
</head>
<body>
<div class="jumbotron container-fluid" style="background-color:#4E4A49;
padding-top:10px; padding-bottom:0px;" >
<a href="ovsms.php" name="logout" style="margin-left:925px; padding-
right:10px; color:#F7008C;"><span class="glyphicon glyphicon-log-out">
</span> LogOut</a>
<h1 style="text-align:center; padding-bottom:20px; margin-top:10px;
margin-bottom:20px; font-family:Lucida Calligraphy; color:#0566c3;">Online
Vehicle Sales Management System</h1>
</div>
<div style="color:black; "class="btn-group btn-group-justified" >
<a href="home.php" class="btn btn-primary" ><span class="glyphicon
glyphicon-home"></span> Home</a>
<a href="about.php" class="btn btn-primary"><span class="glyphicon
glyphicon-education"></span> About Us</a>
<a href="contact.php" class="btn btn-primary"> <span class="glyphicon
glyphicon-envelope"></span> Contact Us</a>
</div>
<div class="list-group" style="width:250px; margin-left:10px;">
<h3 style="text-align:center; color:#0566c3;">Vehicles for...?</h3>
<a style=" color:#0566c3;" href="newpurchase.php" class="list-group-item
">new purchase</a>
<a style=" color:#0566c3;" href="rent.php" class="list-group-item">Rent</a>
</div>
<div class="container-fluid">
<form action="" method="post" >
<div class="form-group">
<input type="text" name="srno" placeholder="Select by Sr.No ....">
</div>
<div class="form-group">
<button type="submit" name="view" class="btn btn-default"
style="color:#F7008C; background-color:#0566c3;" ><span class="glyphicon
glyphicon-ok"></span> Select</button>
</div>
</form>
</div>
<div>
<h1 class="container" style="color:#0566c3;"><span class="glyphicon glyphicon-bed"></span> Vehicles for New Purchase</h1>
<?php
include('DbConnect.php');
$sql = mysql_query("select * from vehicledata");
while ($row = mysql_fetch_array($sql)) {
?>
<table class="table table-striped" class="container-fluid" style="margin:10;">
<form action="newpurchase.php" method="post" enctype="multipart/form-data" >
<tbody>
<tr>
<div class="form-group">
<thead><img width='250' src="<?php echo $row['image']; ?>" /></thead>
</div>
</tr>
<tr><div class="form-group" >
<td>Sr.No <b><?php echo $row['id']; ?></b>
</td><td></td>
</div></tr>
<tr><div class="form-group" >
<td>Company</td>
<td><b><?php echo $row['company']; ?></b>
</td>
</div></tr>
<tr><div class="form-group">
<td>Vehicle Name</td>
<td><b><?php echo $row['vehiclename']; ?></b></td>
</div>
</tr>
<tr><div class="form-group">
<td>Model</td>
<td><b><?php echo $row['model']; ?></b></td>
</div></tr>
<tr>
<div class="form-group">
<td>Fuel Type</td>
<td><b><?php echo $row['fuel']; ?></b></td>
</div></tr>
<tr>
<div class="form-group">
<td>Transmission Type</td>
<td><b><?php echo $row['tranmission']; ?></b></td></div></tr>
<tr><div class="form-group">
<td>Engine</td>
<td><b><?php echo $row['engine']; ?></b></td></div></tr>
<tr><div class="form-group">
<td>Driving Type</td>
<td><b><?php echo $row['drive']; ?></b></td></div></tr>
<tr><div class="form-group">
<td>Mileage (Km/L)</td>
<td><b><?php echo $row['mileage']; ?></b> </td></div></tr>
<tr><div class="form-group">
<td>Price in Rs =/</td>
<td><b><?php echo $row['price']; ?></b></td></div></tr>
<tr><div class="form-group">
<td><br>
<button type="submit" name="add" class="btn btn-default" style="color:#F7008C; background-color:#0566c3;" ><span class="glyphicon glyphicon-ok"></span> Select</button>
</td><td></td>
</div></tr>
</tbody>
</form>
</table>
<?php
}
?>
</div>
<?php
if (isset($_POST['view'])) {
$srno = $_POST['srno'];
$select = mysql_query("select * from vehicledata where id='$srno' ");
if ($ro = mysql_fetch_array($select)) {
?>
<div class="container-fluid"><h1>Your dream car is here...</h1>
<h2>You have to pay <?php echo $ro['price']; ?></h2></div>
<div> <table class="table table-striped" class="container-fluid" style="margin:10;">
<form action="newpurchase.php" method="post" enctype="multipart/form-data" >
<tbody>
<tr>
<div class="form-group">
<thead><img width='250' src="<?php echo $ro['image']; ?>" /></thead>
</div>
</tr>
<tr><div class="form-group" >
<td></b>
</td><td></td>
</div></tr>
<tr><div class="form-group" >
<td>Sr.No <b><?php echo $ro['id']; ?></b>
</td><td></td>
</div></tr>
<tr><div class="form-group" >
<td>Company</td>
<td><b><?php echo $ro['company']; ?></b>
</td>
</div></tr>
<tr><div class="form-group">
<td>Vehicle Name</td>
<td><b><?php echo $ro['vehiclename']; ?></b></td>
</div>
</tr>
<tr><div class="form-group">
<td>Model</td>
<td><b><?php echo $ro['model']; ?></b></td>
</div></tr>
<tr>
<div class="form-group">
<td>Fuel Type</td>
<td><b><?php echo $ro['fuel']; ?></b></td>
</div></tr>
<tr>
<div class="form-group">
<td>Transmission Type</td>
<td><b><?php echo $ro['tranmission']; ?></b></td></div></tr>
<tr><div class="form-group">
<td>Engine</td>
<td><b><?php echo $ro['engine']; ?></b></td></div></tr>
<tr><div class="form-group">
<td>Driving Type</td>
<td><b><?php echo $ro['drive']; ?></b></td></div></tr>
<tr><div class="form-group">
<td>Mileage (Km/L)</td>
<td><b><?php echo $ro['mileage']; ?></b> </td></div></tr>
<tr><div class="form-group">
<td>Price in Rs =/</td>
<td><b><?php echo $ro['price']; ?></b></td></div></tr>
</tbody>
</form>
</table></div>
<?php
}
}
?>
</body>
</html>
Try This:
<td>
<a href='other page url?view=<?php echo $row['id']; ?>'>View</a>
</td>
I have a hide button code which does hide any div or element i want however the problem is i have a data table which displays more than one select option for each row in the table
if the order has 3 items it will display the 3 items with the 3 select options
however the hide button only works for the first one and not for the other 2 each select option has its own button generated
my code is below
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<script>
$(document).ready(function () {
$(".edit_status_combo").change(function (event) {
var row_id = $(this).closest("tr").find(".row_id").val();
var delivery_id = $(this).closest("tr").find(".delivery_id").val();
var status = $(this).closest("tr").find(".edit_status_combo").val();
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/sales/view_delivery",
data: {row_id: row_id, delivery_id:delivery_id, i_status: status}
})
})
})
jQuery(document).ready(function(){
jQuery('#hideshow1').on('click', function(event) {
jQuery('#edit_status_combo').toggle('show');
});
});
</script>
<div class="modal-dialog modal-lg no-modal-header">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<i class="fa fa-2x">×</i>
</button>
<button type="button" class="btn btn-xs btn-default no-print pull-right" style="margin-right:15px;" onclick="window.print();">
<i class="fa fa-print"></i> <?= lang('print'); ?>
</button>
<?php if ($logo) { ?>
<div class="text-center pull-left" style="margin-bottom:20px;" >
<img src="<?= base_url() . 'assets/uploads/logos/' . $biller->logo; ?>"
alt="<?= $biller->company != '-' ? $biller->company : $biller->name; ?>">
</div>
<?php } ?>
<div class="table-responsive">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style = "border-collapse: collapse;" >
<tbody style="font-size: 12px !important;">
<tr>
<td><div class="col-xs-19 text-left"><?= lang("customer"); ?>: <?= $delivery->customer; ?></div></td>
<td><div class="col-xs-19 text-right"><?= lang("sale_reference_no"); ?>: <?= $delivery->sale_reference_no; ?></div></td>
</tr>
<tr>
<td><div class="col-xs-19 text-left"><?= lang("address"); ?>: <?= $delivery->address; ?></div></td>
<td><div class="col-xs-19 text-right"><?= lang("do_reference_no"); ?>: <?= $delivery->do_reference_no; ?></div></td>
</tr>
<tr>
<td><div class="col-xs-19 text-left"></div></td>
<td><div class="col-xs-19 text-right"><?= lang("Estimated Delivery Date"); ?>: <?= $this->sma->hrld($delivery->date); ?></div></td>
</tr>
<tr>
<td><div class="col-xs-19 text-left"></div></td>
<td><div class="col-xs-19 text-right"><?= lang("status"); ?>: <?= $delivery->status; ?></div></td>
</tr>
<tr>
<td><div class="col-xs-19 text-left"></div></td>
<td><div class="col-xs-19 text-right"><?= lang("Staff Name"); ?>: <?= $user->first_name . ' ' . $user->last_name; ?></div></td>
</tr>
</tbody>
</table>
</div>
<h3><?= lang("items"); ?></h3>
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped" >
<thead >
<tr>
<th style="text-align:center; vertical-align:middle;"><?= lang("no"); ?></th>
<th style="vertical-align:middle;"><?= lang("description"); ?></th>
<th style="text-align:center; vertical-align:middle;"><?= lang("quantity"); ?></th>
<th class="status_column_table"><?= lang("product_status"); ?></th>
</tr>
</thead>
<tbody>
<?php $r = 1;
foreach ($rows as $row): ?>
<tr>
<td style="text-align:center; width:40px; vertical-align:middle;"><?= $r; ?></td>
<td style="vertical-align:middle;">
<?= $row->product_code ." - " .$row->product_name .($row->variant ? ' (' . $row->variant . ')' : '');
if ($row->details) {
echo '<br><strong>' . lang("product_details") . '</strong> ' .
html_entity_decode($row->details);
}
?>
</td>
<td style="width: 150px; text-align:center; vertical-align:middle;"><?= $this->sma->formatQuantity($row->unit_quantity).' '.$row->product_unit_code; ?></td>
<td style="text-align:center; width:40px; vertical-align:middle;">
<input class = "row_id" type="hidden" name="row_id_text" value="<?= $row->product_id;?>">
<input class = "delivery_id" type="hidden" name="delivery_id_text" value="<?= $delivery->id;?>">
<div class='no-print'><input type='button' id='hideshow1' value=''></div>
<select id="edit_status_combo" name="item_status">
<option value="delivering" <?= $row->status=='delivering' ? 'selected' : '';?>>Delivering</option>
<option value="delivered" <?= $row->status=='delivered' ? 'selected' : '';?>>Delivered</option>
<option value="waiting" <?= $row->status=='waiting' ? 'selected' : '';?>>Waiting</option>
<option value="returned" <?= $row->status=='returned' ? 'selected' : '';?>>Returned</option>
<option value="wrong" <?= $row->status=='wrong' ? 'selected' : '';?>>Wrong</option>
<option value="damaged" <?= $row->status=='damaged' ? 'selected' : '';?>>Damaged</option>
<option value="missing" <?= $row->status=='missing' ? 'selected' : '';?>>Missing</option>
</select>
</td>
</tr>
<?php
$r++;
endforeach;
?>
</tbody>
</table>
</div>
<div class="table-responsive">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style = "border-collapse: collapse;" >
<tbody style="font-size: 12px !important;">
<tr>
<td width="6%"><div class="form-group pull-left"><?= lang("ccf1", "cf1"); ?>
<?php echo form_checkbox('cf1', 'cf1', $customer->cf1, 'class="form-control" id="cf1"'); ?></div></td>
<td width="6%"><div class="form-group pull-left"><?= lang("ccf2", "cf2"); ?>
<?php echo form_checkbox('cf2', 'cf2', $customer->cf2, 'class="form-control" id="cf2"'); ?></div></td>
<td width="12%"<div class="form-group pull-left"> <?= lang("ccf3", "cf3"); ?>
<?php echo form_checkbox('cf3', 'cf3', $customer->cf3, 'class="form-control" id="cf3"'); ?></div></td>
<td width="12%"><div class="form-group pull-left"><?= lang("ccf4", "cf4"); ?>
<?php echo form_checkbox('cf4', 'cf4', $customer->cf4, 'class="form-control" id="cf4"'); ?></div></td>
<td width="63%"></td>
</tr>
</tbody>
</table>
</div>
<div class="clearfix"></div>
<?php if ($delivery->note) { ?>
<div class="well well-sm">
<p class="bold" style="font-size:11px;"><?= lang("note"); ?>:</p>
<div style="font-size:11px;"><?= $this->sma->decode_html($delivery->note); ?></div>
</div>
<?php } ?>
<p class="bold" style="font-size:11px;"><?= lang("Customer Satisfaction"); ?>:</p>
<input type="text" id="txtbox123">
<br>
<br>
<div class="row">
<div class="col-xs-4 pull-left">
<p style="height:30px; font-size:11px;"><?= lang("received_by"); ?> : </p>
<hr style="height:1px;border:none;color:#333;background-color:#333;">
<p style="font-size:11px;"><?= lang("Receiver/Customer Signature"); ?></p>
</div>
<div class="col-xs-4 pull-right">
<p style="height:30px; font-size:11px;"><?= lang("delivered_by"); ?>: </p>
<hr style="height:1px;border:none;color:#333;background-color:#333;">
<p style="font-size:11px;"><?= lang("stamp_sign"); ?></p>
</div>
</div>
</div>
</div>
</div>
the jquery is at the top
how can i make it so it works each time it is generated below is a example of the select elements
as you can see the first row select element was succesfully hidden the others do not work
enter image description here
You could change the #edit_status_combo and add a class to the element, lets call it .edit_status_combo then you could use a .each() so:
jQuery(document).ready(function(){
jQuery('#hideshow1').on('click', function(event) {
jQuery('.edit_status_combo').each(function(){
jQuery(this).toggle('show');
});
});
});
I'm developing website which advertises used cars for sell in codeigniter. I want to do hit counter for each news by method in controller. When user clicks to news the modal of this news opens and it should add 1 to my hitCounter column in database. I tried many codes and ways to do this but it is not working. If someone please can suggest what to do in this case. Thanks in advance!
Here my controller's method code:
public function clickCounter($id)
{
$this->news_model->set_counter($id);
}
Here my views code:
<?php foreach ($news as $news_item): ?>
<div class="font-icon-list col-lg-3 col-md-3 col-sm-4 col-xs-12" style="padding: 15px;" onclick="document.getElementById('<?php echo $news_item['id']; ?>').style.display='block'; ">
<div class="font-icon-detail"><img src="<?php echo base_url(); echo "images/thumb/images/"; echo $news_item['image_path']; ?>" alt="" style=" max-width: 220px; height:100%;">
<input type="text" value="<?php echo $news_item['location']; echo " - "; echo $news_item['price']; ?>">
<input type="text" value="<?php echo $news_item['telno']; ?>">
</div>
</div>
<div id="<?php echo $news_item['id']; ?>" class="w3-modal">
<div class="w3-modal-content w3-animate-zoom" >
<header class="w3-container">
<span onclick="document.getElementById('<?php echo $news_item['id']; ?>').style.display='none'"
class="w3-closebtn">×</span>
</header>
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12" style="background-color: white; padding:0;">
<table class="table table-hover table-striped" style="white-space:wrap; overflow:hidden;">
<tr>
<td colspan="2" class="text-center"><?php echo $news_item['title']; ?></td>
</tr> <tr>
<td>Сана</td><td><?php echo $news_item['date']; ?></td>
</tr>
<tr >
<td>Нархи</td><td><?php echo $news_item['price']; ?></td>
</tr>
<tr>
<td>Исми ва шарифи</td><td><?php echo $news_item['name']; ?></td>
</tr>
<tr>
<td>Телефон рақам</td><td><?php echo $news_item['telno']; ?></td>
</tr>
<tr>
<td colspan="2" class="text-center">Қўшимча маълумот:</td>
</tr>
<tr>
<td class="text-justify" colspan="2"><?php echo $news_item['info']; ?></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
Here my model code:
public function set_counter($id)
{
$sql = "SELECT * FROM avto WHERE id = ?" ;
$query = $this->db->query($sql, $id);
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row) {
$data['hitCounter'] = $row['hitCounter'];
}
$numHits= $data['hitCounter'];
$numHits = $numHits + 1;
$data = array(
'hitCounter' => $numHits,
);
$this->db->where('id', $id);
$this->db->update('avto', $data);
}
return false;
}
Step 1: Call controller function onClick
<button type="button" class="btn btn-success"
onclick="<?php echo base_url()?>controller/function">Click Here</button>
Step 2: In Controller define respective function and add update query..
you have to update count in table because in real-time counter can't be stored in session as there are multiple users are using website
now add table named as tbl_count and apply below query
$qry = "UPDATE `tbl_count` SET `hits`=`hits` +1 WHERE `news_id` = '".$news_id."'";
Your model function should be something like this
public function set_counter($id)
{
if($id>0)
{
$sql = "UPDATE avto SET hitCounter = hitCounter + 1 WHERE id = ".$id ;
$this->db->query($sql);
}
}
This is cart view
<div id="cart" >
<div id="text">
<?php $cart_check = $this->cart->contents();
// If cart is empty, this will show below message.
if(empty($cart_check))
{
echo 'To add products to your shopping cart click on "Add to Cart" Button';
} ?> </div>
<table id="table" border="0" cellpadding="5px" cellspacing="1px" class="table table-hover" style="padding: 0px;margin: 0px;text-align: center">
<?php
// All values of cart store in "$cart".
if ($cart = $this->cart->contents()): ?>
<tr id= "main_heading">
<td width="5%">Serial</td>
<td width="30%">Name</td>
<td width="20%">Price</td>
<td width="10%">Qty</td>
<td width="25%">Amount</td>
<td width="10%">Cancel Product</td>
</tr>
<?php
// Create form and send all values in "shopping/update_cart" function.
echo form_open('index.php/cart/update_cart');
$grand_total = 0;
$i = 1;
foreach ($cart as $item):
// echo form_hidden('cart[' . $item['id'] . '][id]', $item['id']);
// Will produce the following output.
// <input type="hidden" name="cart[1][id]" value="1" />
echo form_hidden('cart[' . $item['id'] . '][id]', $item['id']);
echo form_hidden('cart[' . $item['id'] . '][rowid]', $item['rowid']);
echo form_hidden('cart[' . $item['id'] . '][name]', $item['name']);
echo form_hidden('cart[' . $item['id'] . '][price]', $item['price']);
echo form_hidden('cart[' . $item['id'] . '][qty]', $item['qty']);
?>
<tr>
<td>
<?php echo $i++; ?>
</td>
<td>
<?php echo $item['name']; ?>
</td>
<td>
$ <?php echo number_format($item['price'], 2); ?>
</td>
<td>
<?php echo form_input('cart[' . $item['id'] . '][qty]', $item['qty'], 'maxlength="3" size="1" style="text-align: center"'); ?>
</td>
<?php $grand_total = $grand_total + $item['subtotal']; ?>
<td>
$ <?php echo number_format($item['subtotal'], 2) ?>
</td>
<td>
<?php
// cancle image.
?>
<a href="<?php echo base_url() ;?>index.php/cart/remove/<?php echo $item['rowid']?>">
<img src="<?php echo base_url(); ?>assets/images/cart/cart_cross.jpg" width='25px' height='20px'>
</a
<?php
// echo anchor('index.php/cart/remove/' . $item['rowid'], $path); ?>
</td>
<?php endforeach; ?>
</tr>
<tr class="info">
<td colspan="2" align="left"> <b>Order Total: $ <span style="font-weight: bold"> <?php
//Grand Total.
echo number_format($grand_total, 2); ?></span></b></td>
<?php // "clear cart" button call javascript confirmation message ?>
<td colspan="4" align="right"><input type="button" class ='fg-button teal' value="Clear Cart" onclick="clear_cart()">
<?php //submit button. ?>
<input type="submit" class ='fg-button teal' value="Update Cart">
<?php echo form_close(); ?>
<!-- "Place order button" on click send "billing" controller -->
<!-- <input type="button" class ='fg-button teal' value="Place Order" onclick="window.location = 'index.php/cart/billing_view'">-->
<button id="placeorder" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="#mdo" style="margin-left: 5px">Place Order</button>
</td>
</tr>
<?php endif; ?>
</table>
</div>
After click on placeholder button(above code) it will open bootstrap model.
Code of that is
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" style="text-align: left">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Tour Inquire Form</h4>
</div>
<?php
$grand_total = 0;
// Calculate grand total.
if ($cart = $this->cart->contents()):
foreach ($cart as $item):
$grand_total = $grand_total + $item['subtotal'];
endforeach;
endif;
?>
<form action="<?php echo base_url();?>index.php/cart/send_mail" method="POST" id="mailform">
<div class="modal-body">
<div class="form-group">
<label for="recipient-name" class="control-label">Name:</label>
<input type="text" class="form-control" name="name">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">E-Mail</label>
<input type="email" class="form-control" name="mail">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">Contact Number</label>
<input type="number" class="form-control" name="mob">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">Total Value of Your Product</label>
<input type="text" class="form-control" name="price" value="<?php echo $grand_total;?>" readonly>
</div>
<div class="form-group">
<label for="message-text" class="control-label">Message:</label>
<textarea class="form-control" id="message-text" rows="5" name="msg"></textarea>
</div>
</div>
<div class="modal-footer">
<input type="button" class="btn btn-default" data-dismiss="modal" value="Close">
<input type="submit" class="btn btn-primary" name="submit" value="Send Mail">
</div>
</form>
</div>
</div>
</div>
After user click on Send Mail, I need to send mail get data(html codes) from some other div(Mentioned below, Name mail_table)
and data should send to my mail controller.
<div id="mail_table" style="display: none">
<table cellpadding="6" cellspacing="1" style="width:100%" border="0">
<tr>
<th>QTY</th>
<th>Product Name</th>
<th style="text-align:right">Item Price</th>
<th style="text-align:right">Sub-Total</th>
</tr>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<tr>
<td><?php echo $items["qty"] ?></td>
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
<p>
<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>
<strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />
<?php endforeach; ?>
</p>
<?php endif; ?>
</td>
<td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td>
<td style="text-align:right">$<?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="2"> </td>
<td class="right"><strong>Total</strong></td>
<td class="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
</div>
all works fine with ajax.
<script>
$(function(){
$( "#placeorder" ).click(function(event){
event.preventDefault();
var htmlString = $("#mail_table").html();
$.ajax({
type : 'post',
url : '<?php echo base_url();?>index.php/cart/send_mail',
data : $('#form').serialize() + "table" + htmlString
});
});
});
</script>
but in controller when I assign data to
public function send_mail()
{
$name = $_POST['name'];
$mail = $_POST['mail'];
$mob = $_POST['mob'];
$price = $_POST['price'];
$msg = $_POST['msg'];
// $to =
$to = 'mail#gmail.com';
$to = 'my#gmail.com';
$subject = 'Enquiry from ' .$name;
$message = $_POST['table']; //Line 144
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
// $headers .= 'From: '.$_REQUEST['email'];
if(mail($to, $subject, $message, $headers))
{
}
}
But I'm getting error
A PHP Error was encountered
Severity: Notice
Message: Undefined index: table
Filename: controllers/cart.php
Line Number: 144
any idea???
Problem is this line of code in your view ajax. With this code table not send in your parameter. Also your form id is mailform
data : $('#form').serialize() + "table" + htmlString
It would be
data : $('#mailform').serialize() + "&table=" + encodeURIComponent(htmlString)