How to get the previous day (continous) - javascript

Hello guys I want to get the information of previous date or last day only when I press the button and it will display the all information last day (saturday) and if I click the button again it will shows information of last last day (friday) and if I click it again (thursday) thanks for helping me guys
EDITED:
generate_attendance.php
if(isset($_POST['submit1'])){
$prev_date= date('Y/m/d',strtotime("-1 days"));
$query=mysqli_query($dbcon,"select * from attendance where date_added '$prev_date'")or die(mysql_error());
while($row=mysqli_fetch_array($query)){
$attendance_id=$row['attendance_id'];
?>
<tr>
<td><?php echo $row['lastname'].', '.$row['firstname']; ?></td>
<td><?php echo $row['course']; ?></td>
<td><?php echo $row['type']; ?></td>
<td><?php echo $row['year_level']; ?></td> <td><?php echo $row['date_added']; ?</td>
</tr>
<?php
<div class="controls">
<button name="submit1" type="submit1" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Previous Day</button>
</div>
</div>
generate_attendance.php (full code)
<div class="container">
<div class="margin-top">
<div class="row">
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong><i class="icon-user icon-large"></i> Attendance Report</strong>
</div>
<div class="span12">
<center class="title">
<h1>Attendance List</h1>
</center>
<div class="pull-right">
<i class="icon-print icon-large"></i> Print
</div>
<form method="post">
<div class="span3">
<div class="control-group">
<label class="control-label" for="inputEmail"><!-- Attendance Report --></label>
<div class="controls">
<label class="control-label" for="inputEmail">From</label>
<div class="controls">
<input type="date" name="from_date" id="date1" alt="date" class="IP_calendar" title="d/m/Y">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">To Date</label>
<div class="controls">
<input type="date" name="to_date" id="date2" alt="date" class="IP_calendar" title="d/m/Y">
<!-- <input type="text" class="w8em format-d-m-y highlight-days-67 range-low-today" name="due_date" id="sd" maxlength="10" style="border: 3px double #CCCCCC;" required/> -->
</div>
</div>
<div class="control-group">
<div class="controls">
<button name="submit" type="submit" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Search</button>
</div>
</div>
<div class="controls">
<button name="submit1" type="submit1" class="btn btn-success"><i class="icon-minus-sign icon-large"></i> Previous Day</button>
</div>
</div>
<div class="span8">
<div class="alert alert-success"><strong>Attendance Report</strong></div>
<table cellpadding="0" cellspacing="0" border="0" class="table" id="example">
<thead>
<tr>
<th>Name</th>
<th>Program Code</th>
<th>Type</th>
<th>Year level</th>
<th>Date Log-in</th>
</tr>
</thead>
<tbody>
<?php
if(isset($_POST['submit'])){
$from_date=$_POST['from_date'];
$to_date=$_POST['to_date'];
$query=mysqli_query($dbcon,"select * from attendance where date_added between '$from_date' and '$to_date'")or die(mysql_error());
while($row=mysqli_fetch_array($query)){
$attendance_id=$row['attendance_id'];
?>
<tr>
<td><?php echo $row['lastname'].', '.$row['firstname']; ?></td>
<td><?php echo $row['course']; ?></td>
<td><?php echo $row['type']; ?></td>
<td><?php echo $row['year_level']; ?></td>
<td><?php echo $row['date_added']; ?></td>
</tr>
<?php
}}
?>
<?php
if(isset($_POST['submit1'])){
$prev_date= date('Y/m/d',strtotime("-1 days"));
$query=mysqli_query($dbcon,"select * from attendance where date_added between '$curr_date' and '$prev_date'")or die(mysql_error());
while($row=mysqli_fetch_array($query)){
$attendance_id=$row['attendance_id'];
?>
<tr>
<td><?php echo $row['lastname'].', '.$row['firstname']; ?></td>
<td><?php echo $row['course']; ?></td>
<td><?php echo $row['type']; ?></td>
<td><?php echo $row['year_level']; ?></td>
<td><?php echo $row['date_added']; ?></td>
</tr>
<?php
}}
?>
</tbody>
</table>
</form>
</div>
</div>
</div>
</div>
</div>

Probably pass a query parameter, that indicates how many dates it should subtract, so the url looks like this:
yourphpscript.php? days = 3
Then you can get that in the php, and change the date building:
$days = $_GET["days"];
if(!isset($days)){
$days = 1;
}
$days = intval($days);
$prev_date= date('Y/m/d',strtotime("-".$days." days"));
So now the only thing thats missing, is to change the url of the next request, which would look like this:
<form href="?days=<?php echo $days+1;?>" >

You can send the currently displayed date back to the server within the POST-data.
<input type="hidden" name="currently_displayed" value="<?php echo $prev_date ?>">
<button name="submit1" type="submit1" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Previous Day</button>
Then within your PHP:
if (isset($_POST['currently_displayed'])) {
// Convert as unix-timestamp
$currentlyDisplayed = strtotime($_POST['currently_displayed']);
} else {
// Not posted, assuming user wants to see yesterday (thus $currentlyDisplayed should be today/now)
$currentlyDisplayed = time();
}
// strtotime( $formatString, $relativeTo );
$prev_date= date('Y/m/d',strtotime("-1 days", $currentlyDisplayed));

I would suggest you to use javascript/JQuery AJAX request instead, you can change it instantly and you can KEEP TRACK of how many clicks you did for the number of previous days ! You don't need if isset POST submit1 anymore.
On the button "Submit1" , have an onclick function to AJAX request that sends the value of numberPrevDays. Make sure to KEEP track of this clicks (Heck you can even have another button which is for the next day). There are several ways to do this. Either to just have a global variable that will keep incrementing (or decrementing) BEFORE sending to the AJAX request
Have a seperate file & function php where the it receives the number of Prev days. This file will process the data and output response json your SQL mysqli_fetch_array data
With that output response, just empty and reload the table with the new data
Sorry I didn't write the actual code

Related

Clicking on any radio button in my created list results in only the first <select> field being activated

Here is the video in specific from what i mean. It is hosted on my personal drive
video
Here is my code
<?php
$pagetitle="Search Report";
include "includes/header.php";
include("config.php");
include("connection.php");
error_reporting(E_ALL ^ E_DEPRECATED);
$name=$_GET['filo'];
$ksm=$_GET['kisim'];
$drs=$_GET['hders'];
$ndrs=$_GET['dname'];
$tch=$_GET['tname'];
?>
<script>
//Here Is javascript code
function enable() {
document.getElementById('option').disabled=false;
}
</script>
<style type="text/css">
input[type="radio"]{
margin: 0px 4px 0px;
}
</style>
<div class="container">
<div class="row">
<div class="templatemo-line-header" style="margin-top: 0px;" >
<div class="text-center">
<hr class="team_hr team_hr_left hr_gray"/><span class="span_blog txt_darkgrey txt_orange"> </span>
<hr class="team_hr team_hr_right hr_gray" />
</div>
</div>
</div>
<div class="table-responsive">
<table class="ui celled table table table-hover">
<form action="check.php" method="get">
<thead>
<tr>
<th>Adı ve Soyadı</th>
<th>Dersin Adı</th>
<th>Dersin Saatı</th>
<th>Öğretim Elemanı</th>
<th>Durum</th>
<th>Sebepi</th>
<th>ID</th>
</tr>
</thead>
<tbody>
<?php
$query3=mysqli_query($connect,"select * from student where filo='$name' and kisim='$ksm' ORDER BY student_name");
$arra=-1;
while($row=mysqli_fetch_row($query3))
{
$arra++;
?>
<tr>
<td><?php echo $row[1] ?></td>
<input type="hidden" value="<?php echo $row[1] ?>" name="std_name[]">
<td><?php echo $ndrs ?></td>
<input type="hidden" value="<?php echo $ndrs ?>" name="ndrs[]">
<td><?php echo $drs ?></td>
<input type="hidden" value="<?php echo $drs?>" name="drs[]">
<td><?php echo $tch ?></td>
<input type="hidden" value="<?php echo $tch ?>" name="tch[]">
<td>
///////HERE IS ONE PART OF THE CODE
<input type="radio" name="attendance[<?php echo "$arra" ?>]" value="Mevcut" checked="checked" >Mevcut
<input type="radio" name="attendance[<?php echo "$arra" ?>]" onclick="enable()" value="Gayri">Gayrı
</td>
<td>
<select class="form-control" id="option" name="option[<?php echo "$arra" ?>]" disabled >
<option selected value="Mevcut">Mevcut</option>
<option value="Vizite">Vizite</option>
<option value="Hst Muayene">Hst Muayene</option>
<option value="Izinli">Izinli</option>
</select>
</td>
<td><?php echo $row[0] ?>
<input type="hidden" value="<?php echo $row[0] ?>" name="id[]">
</td>
</tr>
<?php } ?>
</tbody>
</table>
<button type="submit" class="btn btn-success btn-lg btn-block" name="submit2">Gönder</button>
</form>
</div><!--table-responsive-->
</div><!--row-->
</div><!--container-->
<?php include "includes/footer.php"; ?>
I try to explain my problem.
Scenario is like that. Some infos are taken from a submit form and with this infos i create a list then created list has 2 radio buttons and by default a disabled select area.
The problem is here. When i click on "Gayri" button field must be activated for every person in that list instead of that just the first field is activated.
Can anyone help me? I want for every possible person in the list when i click on "gayri" radio button the field to be activated.

how to save a table in xhr.responseText

I've been trying to do a fast research with Ajax and i want to get a html table inside a xhr.responseText to next get a new research result and i was doing this but i didn't find a way to do it can u please help me resolving it if possible ?
Javascript Function
function changement(str) {
xhr = new XMLHttpRequest();
var input = document.getElementById('rech').value;
xhr.open('GET','?controller=livres&action=search&val=1316', true);
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
document.getElementById("tab").innerHTML = xhr.responseText;
alert(xhr.responseText);
}
};
}
Controller
public function search()
{
if(!isset($_GET['val']))
{
return call('pages','error');
}
$livre= Livre::findByCin($_GET['val']);
//require_once('views/livres/index.php');
}
}
?>
Model Function
public static function findByCin($cin)
{
$db=Db::getInstance();
$cin=intval($cin);
$req=$db->prepare("SELECT * FROM document where ref like '%".$cin."%'");
$req->execute();
$list=[];
foreach ($req->fetchAll() as $temp)
{
$Livre=new Livre();
$Livre->setReference($temp['ref']);
$Livre->setNom($temp['nom']);
$Livre->setDateCreation($temp['date_creation']);
$Livre->setPrix($temp['prix']);
$Livre->setAuteur($temp['auteur']);
$Livre->setnbPages($temp['nbrPages']);
$list[]=$Livre;
}
return $list;
}
HTML page
<div class="box">
<div class="col-lg-12">
<hr>
<h2 class="intro-text text-center">
<strong>Liste des Livres</strong>
</h2>
<hr> <br>
<div class="row">
<div class="col-sm-6">
<a class="pull-left btn btn-default" href="?controller=chercheurs&action=add">
Ajouter Livre</a>
<div class="col-sm-6">
<form action="?controller=livres&action=search" method="POST">
<div class="input-group">
<input type="search" onkeyup="changement(this.value)" name="search" class="form-control" placeholder="Recherche par Réference" id="rech">
<span class="input-group-btn">
<button type="submit" class="btn btn-default" > Filtrer </button>
</span>
</div>
</form>
</div>
</div></div><br>
<div class="table-responsive" id="tab">
<table class="table table-stripped"><thead>
<tr>
<th>Réference</th><th>Nom</th><th>DateCreation</th><th>Prix</th><th>Auteur</th><th>NbrPages</th>
</tr> </thead>
<tbody>
<?php foreach ($livre as $livr) {?>
<tr>
<td><?php echo $livr->getReference(); ?></td>
<td><?php echo $livr->getNom(); ?></td>
<td><?php echo $livr->getDateCreation(); ?></td>
<td><?php echo $livr->getPrix(); ?></td>
<td><?php echo $livr->getAuteur(); ?></td>
<td><?php echo $livr->getnbPages(); ?></td>
<td>
<a class="btn btn-danger" href="?controller=livres&action=delete&id=<?php
echo $livr->getReference(); ?>">
Supprimer </a>
<a class="btn btn-primary" href="?controller=livres&action=edit&id=<?php
echo $livr->getReference(); ?>">
Modifier </a
</td>
</tr> <?php } ?>
</tbody> </table>
</div></div></div></div>
thanks .

Cart block not updating codeigniter

I have this controller:
<?php
class Cart extends CI_Controller{
public $paypal_data = '';
public $tax;
public $shipping;
public $total = 0;
public $grand_total;
/*
*Cart Index
*/
public function index(){
//Load view
$data['main_content'] = 'cart';
$this->load->view('layouts/main', $data);
}
/*
*Add To Cart
*/
public function add(){
//Item data
$data = array(
'id'=> $this->input->post('item_number'),
'qty'=> $this->input->post('qty'),
'price'=> $this->input->post('price'),
'name'=> $this->input->post('title'),
);
//print_r($data);die();
//Insert Into cart-block
$this->cart->insert($data);
redirect('products');
}
}
And I have the view file which uses this controller:
<div class="cart-block">
<form action="cart/update" method="post">
<table cellpadding="6" cellspacing="1" style="width:100%" border="0">
<tr>
<th>QTY</th>
<th>Item Description</th>
<th style="text-align:right">Item Price</th>
</tr>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items) : ?>
<input type="hidden" name="<?php echo $i. '[rowid]'; ?>" value="<?php echo $items['rowid']; ?>" />
<tr>
<td><input type="text" name="<?php echo $i.'[qty]'; ?>" value="<?php echo $items['qty']; ?>" maxlength="3" size= "5"</td>
<td><?php echo $items['name']; ?></td>
<td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td></td>
<td class="right"><strong>Total</strong></td>
<td class="right" style="text-align:right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<br>
<p><button class="btn btn-default" type="submit">Update Cart</button>
<a class="btn btn-default" href="cart">Go To Cart</a></p>
</form>
</div>
<div class="panel panel-default panel-list">
<div class="panel-heading panel-jeading-dark">
<h3 class="panel-title">
Categories
</h3>
</div>
<!--List group -->
<ul class="list-group">
<?php foreach(get_categories_h() as $category) : ?>
<li class="list-group-item"><?php echo $category->name; ?></li>
<?php endforeach; ?>
</ul>
I apologize that I can't show you the actual website because it's not online but based on the above snippets can any point out an error in the view file or controller that causes the shopping cart not to update?
I'm following a video tutorial but it seems I'm doing something wrong. Here is the video: https://youtu.be/ajt_DJMS5FM?t=13m45s
Your form action is cart/update your function in the controller is add?
Change the form action to cart/add. Or write an cart/update function.
Firstly change the Form Action action="cart/update" to
action="<?php echo base_url();?>cart/add" and apply die(); and test it
load the cart library in controller
$this->load->library('cart');

How to Create a Shopping Cart using Session in PHP

I'm having trouble creating a shopping cart. How do I make the output so that when I click the add cart button on my products table, it will appear on the cart?
//Product List
<?php
$query = "SELECT * FROM products";
$exec = mysqli_query($connection, $query);
while ($row = mysqli_fetch_array($exec)) {
$product_id = $row['product_id'];
$product_name = $row['product_name'];
$product_quantity = $row['quantity'];
$product_price = $row['sell_price'];
?>
<tr>
<td class="text-center"><?php echo $product_id; ?></td>
<td><?php echo $product_name; ?></td>
<td><?php echo $product_price; ?></td>
<td><?php echo $product_quantity; ?></td>
<td class="text-center">
<div class="btn-group">
<a href="add_sales.php?action=add&product_id=<?php echo $product_id; ?>" class="btn btn-xs btn-info" data-toggle="tooltip" title="Select">
<span class="fa fa-shopping-cart"></span>
</a>
</div>
</td>
</tr>
<?php } ?>
Item Details Panel
if (isset($_GET['product_id'])) {
$prod_id = $_GET['product_id'];
$selectProd = "SELECT * FROM products WHERE product_id = $prod_id";
$execProd = mysqli_query($connection, $selectProd);
while ($row = mysqli_fetch_array($execProd)) {
$prod_name = $row['product_name'];
$prod_price = $row['sell_price'];
$quantity = $row['quantity'];
?>
<div class="panel-body">
<div class="col-md-2">
<div class="form-group">
<label for="">Item ID</label>
<input type="text" class="form-control" value="<?php echo $prod_id; ?>" readonly>
</div>
</div>
<div class="col-md-7">
<div class="form-group">
<label for="">Item Name</label>
<input type="text" class="form-control" value="<?php echo $prod_name ?>" readonly>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="">Unit Price</label>
<input type="text" class="form-control" value="<?php echo $prod_price; ?>" readonly id="unitPrice">
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label for="">Available Qty</label>
<input type="text" class="form-control" value="<?php echo $quantity ?>" readonly>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="">Sale Qty</label>
<input type="number" class="form-control" id="saleQty" name="saleQty">
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label for="">Total Amount</label>
<input type="text" class="form-control" id="totalSale" name="saleTotal" readonly>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<input type="submit" value="Add to Cart" class="btn btn-info form-control" formnovalidate>
</div>
</div>
Cart
<!-- Start of Customer's Cart -->
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<strong>
<span class="fa fa-shopping-cart"></span>
<span>Customer's Cart</span>
</strong>
</div>
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th>Product ID</th>
<th>Product Name</th>
<th>Product Quantity</th>
<th>Product Amount</th>
<th>Total Amount</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- End of Customer Cart -->
Ordering Page Flow (GIF)
None of your input element have name attributes so (I think) when you submit the form, the URL query parameters (if the form has GET method) or the request body parameters (POST method) won't be available and you can't "catch" the act of someone submitting the order. If you add them and handle the form submission (say by ifing on a isset($_POST['order']) you can INSERT the order into the DB and render the cart from the DB table. Also look into http://php.net/manual/en/mysqli.prepare.php to avoid SQL injection.

Search result on click of button in popup

I want to display search result on click of button, but my code is giving me the search result without click on button.
I think it's giving me the query result not the search result.
This code is working fine when I display the result on the page, but as per my requirement I want to display the search result on a popup.
I have used jquery popup.
<body><form action="#" method="POST"><body><form action="#" method="POST"><div data-role="page">
<div data-role="main" class="ui-content" >
Smart Search
</div>
<div data-role="popup" id="a" class="col-sm-6 ui-content">
<div class="input-group col-sm-8">
<input type="text" name="query" class="form-control" placeholder="Search Products to Buy..." " />
<span class="input-group-btn">
<button name ="search_btn" id ="search class="btn btn-warning" type="submit" value="Search" style="background-color:orange;">Search</button>
</span>
</div><div class="input-group col-sm-8 " ><table class="table table-hover">
<thead >
<tr bgcolor="#1E90FF">
<th>Products</th>
<th>Details</th>
<th>Retailers</th>
<th>Price</th>
<th>Buy</th>
</tr>
</thead>
</div><?php
error_reporting(0);
mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
mysql_select_db("wordpress") or die(mysql_error());
?><?php $query = $_POST['query']; $query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results=mysql_query("select feed_product_image,feed_product_name,price,deeplink,image from wp_pc_products_merchants e,wp_pc_products w where e.slug=w.id_merchant and feed_product_name LIKE '%".$query."%'") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0)
{
while($results = mysql_fetch_array($raw_results))
{ ?><div class="input-group col-sm-8" style="text-align:center;margin-top:10px;"><tbody>
<tr>
<td><img src = "<?php echo $results['feed_product_image']; ?>" style="object-fit:contain;height:70px;width:100px;" /></td>
<td><?php echo "<p>".$results['feed_product_name']. "</p>" ; ?></td>
<td><img src = "<?php echo $results['image']; ?>" style="background-size:contain;height:40px;width:120px;" /></td>
<td><?php echo '<i class="fa fa-inr"> '.$results['price']. '</i>'.".00" ; ?></td>
<td>Buy now</td>
</tr>
</tbody>
</div>
<?php
}
}
else
{ // if there is no matching rows do following
echo "No results";
}
?>
</div>
</form>
</div>
This will give you search results in modal popup. I have changed your code around a bit. You can popup in case of no search results too.
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="main" class="ui-content" >
Smart Search
</div>
<div data-role="popup" id="a" class="col-sm-6 ui-content">
<div class="input-group col-sm-8">
<form method="POST">
<input type="text" name="query" class="form-control" placeholder="Search Products to Buy..." " />
<span class="input-group-btn">
<button name ="search_btn" id ="search" class="btn btn-warning" type="submit" value="Search" style="background-color:orange;">Search</button>
</span>
</form>
</div>
<?php
if(isset($_POST['query']) && $_POST['query']!="" ) {
error_reporting(0);
mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
mysql_select_db("wordpress") or die(mysql_error());
$query = $_POST['query']; $query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results=mysql_query("select feed_product_image,feed_product_name,price,deeplink,image from wp_pc_products_merchants e,wp_pc_products w where e.slug=w.id_merchant and feed_product_name LIKE '%".$query."%'") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0)
{
?>
<div class="input-group col-sm-8 modal-box" id="popup" title="Search Results" style="text-align:center;margin-top:10px;">
<table class="table table-hover">
<thead >
<tr bgcolor="#1E90FF">
<th>Products</th>
<th>Details</th>
<th>Retailers</th>
<th>Price</th>
<th>Buy</th>
</tr>
</thead>
<tbody>
<?php
while($results = mysql_fetch_array($raw_results))
{ ?>
<tr>
<td><img src = "<?php echo $results['feed_product_image']; ?>" style="object-fit:contain;height:70px;width:100px;" /></td>
<td><?php echo "<p>".$results['feed_product_name']. "</p>" ; ?></td>
<td><img src = "<?php echo $results['image']; ?>" style="background-size:contain;height:40px;width:120px;" /></td>
<td><?php echo '<i class="fa fa-inr"> '.$results['price']. '</i>'.".00" ; ?></td>
<td>Buy now</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
}
else
{ // if there is no matching rows do following
echo "No results";
}
}
?>
</div>
</form>
</div>
<script>
$(function() {
$( "#popup" ).dialog();
});
</script>

Categories