How to know what is the pangkat of branches i am selected? - php

<label>Branches</label>
<br>
<script type="text/javascript">
<!--
document.write('<textarea class="form-control" style="resize:none;" id="area" rows="3" readonly="readonly"></textarea>')
function updateArea (e) {
document.getElementById('area').value = '';
for (var i=0; i<e.form.elements.length; i++){if (e.form.elements[i].type == 'checkbox' && e.form.elements[i].checked) {document.getElementById('area').value += e.form.elements[i].nextSibling.data; document.getElementById('area').value += '\n';}};
}
// -->
</script>
<p>
<div class="form-control" style="float:left;
height: 100px;
overflow: auto;">
<?php
$select = "SELECT * FROM branches WHERE access = 'User'";
if($result = mysqli_query($conn, $select)){
while ($row = mysqli_fetch_array($result)) {
$brid = $row['brid'];
?>
<input type="checkbox" name="brid[]" value="<?php echo $brid; ?>" onclick="updateArea(this)"><?php echo $brid; ?>
<input type="hidden" name="pangkat" value="<?php echo $pangkat; ?>">
<br>
<?php
}
}
?>
</div>
here is the code i am selecting brid from branches table i already know how to insert multiple rows of selected branches to database i want to know how to insert the pangkat of branches am i selecting.
<?php
require '../db/db.php';
$smsid = $_POST['smsid'];
$brid = $_POST['brid'];
$pangkat = $_POST['pangkat'];
$smssubject = $_POST['smssubject'];
$smscontent = $_POST['smscontent'];
$smsfrom = $_POST['smsfrom'];
for ($i = 0; $i<sizeof($brid); $i++ ){
$insert = $conn->query("INSERT INTO messages(sms_id,brid,pangkat,subject,message,from_brid,datesent)
VALUES('$smsid', '".$brid[$i]."','$pangkat',
'$smssubject','$smscontent','$smsfrom',NOW())");
echo "<script>alert('The Message is successfully sent');</script>";
echo "<script>window.location.assign('../load/amessages.php')</script>";
}?>
here is my action page to insert brid but the pangkat is always blank any help?

<?php
require '../db/db.php';
$smsid = $_POST['smsid'];
$brid = $_POST['brid'];
// $pangkat = $_POST['pangkat'];
$smssubject = $_POST['smssubject'];
$smscontent = $_POST['smscontent'];
$smsfrom = $_POST['smsfrom'];
for ($i = 0; $i<sizeof($brid); $i++ ){
$select = $conn->query(" SELECT * FROM branches WHERE brid = '".$brid[$i]."' ");
while($rows = mysqli_fetch_array($select)){
$pangkat = $rows['pangkat'];
$insert = $conn->query("INSERT INTO messages(sms_id,brid,pangkat,subject,message,from_brid,datesent)
VALUES('$smsid', '".$brid[$i]."','$pangkat',
'$smssubject','$smscontent','$smsfrom',NOW())");
echo "<script>alert('The Message is successfully sent');</script>";
echo "<script>window.location.assign('../load/amessages.php')</script>";
}
}?>
problem solved thanks!

Related

Update multiple record with single query in database using php [duplicate]

This question already has an answer here:
Post form and update multiple rows with mysql
(1 answer)
Closed last year.
I am making an invoice in PHP where multiple products are inserted at once into one table and there grand total goes to another table. I am trying to UPDATE the invoice in MYSQL and PHP. When I press the submit button, the multiple records data from the form goes to the update.php but the query does not run.
database.php
<?php
$connect = mysqli_connect('localhost','root','','invoice');
if (!$connect){
die("Connection failed: " . mysqli_connect_error());
}
?>
edit_invoice.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
table,tr,td,th { border: 1px black solid;}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
Back to Invoice List<br><br>
<?php
include('database.php');
$invoice_number = $_GET['invoice_number'];
$sql = "SELECT * from invoice where invoice_number = '$invoice_number' ";
$query = mysqli_query($connect, $sql);
if ($query->num_rows > 0) {
// output data of each row
$fetch = $query->fetch_assoc();
}
?>
<form method="POST" action="update_invoice.php">
<table>
<thead>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Width</th>
<th>Height</th>
<th>Total</th>
<th>Action</th>
</thead>
<?php
$sql2 = "SELECT * from invoice_order where invoice_number = '$invoice_number' ";
$query2 = mysqli_query($connect, $sql2);
if ($query2->num_rows > 0) {
// output data of each row
$srno = 1;
$count = $query2->num_rows;
for ($i=0; $i < $count; $i++) {
while($row = $query2->fetch_assoc()) {
?>
<tbody id="product_table">
<tr>
<td><input type="text" name="product[]" value="<?php echo $row["product"]; ?>"></td>
<td><input type="text" name="price[]" value="<?php echo $row["price"]; ?>"></td>
<td><input type="text" name="quantity[]" value="<?php echo $row["quantity"]; ?>"></td>
<td><input type="text" name="width[]" value="<?php echo $row["width"]; ?>"></td>
<td><input type="text" name="height[]" value="<?php echo $row["height"]; ?>"></td>
<td><input type="text" name="total[]" value="<?php echo $row["total"]; ?>" class="totalPrice" readonly></td>
<td><input type="button" value="X" onclick="deleteRow(this)"/></td>
</tr>
</tbody>
<?php
}
}
} else {
echo "No Record Found";
}
?>
<input type="button" name="submit" value="Add Row" onclick="add_fields();">
<span>Invoice Date:<input type="date" value="<?php echo $fetch["invoice_date"]; ?>" name="invoice_date"></span>
<span>Invoice #:<input type="text" name="invoice_number" value="<?php echo $fetch["invoice_number"]; ?>" readonly></span>
<span>Select Customer:
<select name="to_user" class="form-control">
<option><?php echo $fetch["customer_id"]; ?></option>
<?php
include('database.php');
$sql = mysqli_query($connect, "SELECT * From customer");
$row = mysqli_num_rows($sql);
while ($row = mysqli_fetch_array($sql)){
echo "<option value='". $row['customer_id'] ."'>" .$row['customer_id'] ." - " .$row['customer_name'] ."</option>" ;
}
?>
</select>
</span>
</table>
<span>Grand Total<input type="text" name="grandtotal" id="grandtotal" value="<?php echo $fetch["grandtotal"]; ?>" readonly></span><br><br>
<span>Paid Amount<input type="text" name="paid" id="paid" value="<?php echo $fetch["paid"]; ?>"></span><br><br>
<span>Balance<input type="text" name="balance" id="balance" value="<?php echo $fetch["balance"]; ?>" readonly></span><br><br>
<input type="submit" name="send" value="Submit">
</form>
</body>
<script>
const table = document.getElementById('product_table');
table.addEventListener('input', ({ target }) => {
const tr = target.closest('tr');
const [product, price, quantity, width, height, total] = tr.querySelectorAll('input');
var size = width.value * height.value;
var rate = price.value * quantity.value;
if (size != "") {
total.value = size * rate;
}else{
total.value = rate;
}
totalPrice();
});
function add_fields() {
var row = document.createElement("tr");
row.innerHTML =
'<td><input type="text" name="product[]"></td>' +
'<td><input type="text" name="price[]"></td>' +
'<td><input type="text" name="quantity[]"></td>' +
'<td><input type="text" name="width[]" value="0"></td>' +
'<td><input type="text" name="height[]" value="0"></td>' +
'<td><input type="text" name="total[]" class="totalPrice" readonly></td>' +
'<td><input type="button" value="X" onclick="deleteRow(this)"/></td>';
table.appendChild(row);
}
function deleteRow(btn) {
var row = btn.parentNode.parentNode;
row.parentNode.removeChild(row);
totalPrice();
}
function totalPrice() {
var grandtotal = 0;
var paid = 0;
$(".totalPrice").each(function() {
grandtotal += parseFloat($(this).val());
paid = grandtotal;
});
$("#grandtotal").val(grandtotal);
$("#paid").val(paid);
}
$(document).ready(function() {
$('#paid').on('input', function() {
grandtotal = $("#grandtotal").val();
paid = $("#paid").val();
balance = parseFloat(grandtotal) - parseFloat(paid);
$("#balance").val(balance);
})
});
</script>
</html>
Update_invoice.php
<?php
include('database.php');
if (isset($_POST['send'])) {
$product = $_POST['product'];
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$width = $_POST['width'];
$height = $_POST['height'];
$total = $_POST['total'];
$customer_id = $_POST['to_user'];
$invoice_date = $_POST['invoice_date'];
$invoice_number = $_POST['invoice_number'];
$grandtotal = $_POST['grandtotal'];
$paid = $_POST['paid'];
$balance = $_POST['balance'];
$amount_status = "";
if ($grandtotal == $paid) {
$amount_status = "Paid";
} elseif ($grandtotal == $balance) {
$amount_status = "Due";
} else {
$amount_status = "Partial";
}
// Start of Updating data to invoice_order table
for ($i = 0; $i < count($_POST['total']); $i++) {
if ($i <> count($_POST['total'])) {
$sql = "UPDATE invoice_order SET invoice_number = '$invoice_number' , product = '$_POST['product'][$i]', price = '$_POST['price'][$i]' , quantity = '$_POST['quantity'][$i]', width = '$_POST['width'][$i]' , height = '$_POST['height'][$i]' , total = '$_POST['total'][$i]' WHERE invoice_number='$invoice_number' ";
$query = mysqli_query($connect, $sql);
if ($query) {
header('location: list_invoice.php');
} else {
echo "Unable to enter records in invoice_order table";
}
}
}
// End of updating data to invoice_order table
// Start of updating data to invoice table
$sql2 = "UPDATE invoice SET customer_id = '$customer_id', grandtotal = '$grandtotal', invoice_number = '$invoice_number', invoice_date = '$invoice_date', paid = '$paid', balance = '$balance', amount_status = '$amount_status' WHERE invoice_number='$invoice_number' ";
$query2 = mysqli_query($connect, $sql2);
if ($query2) {
header('location: list_invoice.php');
} else {
echo "Unable to enter record in invoice table";
}
// End of updating data to invoice table
}
?>
The approach you are using is not the preferred way of doing the job. Use mysql prepare statement. This will make the code clean, easy to read and secured. Here is the link you can refer Mysql Prepared Statement in PHP

JQuery and PHP - Inserting multiple rows

Tried and tried multiple asked questions with solutions here, but all were not solving my problem.
This form uses JQuery to dynamically add a set of fields. The problem is that MySQL does not insert the set of data upon submission. Here is the code:
HTML:
<form action="new_purchase_order%20(1).php" method="post">
Supplier
<select name="supplier[]">
<option value="">Select supplier...</option>
<?php
$get_supps = "select supplier_name from suppliers";
$supplist = mysqli_query($db, $get_supps);
//get suppliers available in the database
while($row = mysqli_fetch_assoc($supplist)) {
?>
<option value="<?php echo $row['supplierID'] ?>"><?php echo $row['supplier_name'] ?></option>
<?php } ?>
</select><br /><br />
<select name="item[]">
<option value="">Select item...</option>
<?php
$get_items = "select name from raw_materials";
$itemlist = mysqli_query($db, $get_items);
//get all raw materials available in the database
while($row = mysqli_fetch_assoc($itemlist)) {
?>
<option value="<?php echo $row['materialID'] ?>"><?php echo $row['name'] ?></option>
<?php } ?>
</select>
<!--enter its unit price-->
<input type="text" name="price[]" placeholder="Unit Price">
<!--enter the qty of the item selected-->
<input type="number" name="qty[]" min=1 placeholder="Qty" width="30px">
ADD
PHP:
<?php
include("session.php");
if (isset($_POST['submit'])) {
$supplier = $_POST['supplier'];
$item = $_POST['item'];
$qty = $_POST['qty'];
$price = $_POST['price'];
for ($i=0; $i < count($item); $i++) {
$supplier[$i] = mysqli_real_escape_string($db, $supplier[$i]);
$item[$i] = mysqli_real_escape_string($db, $item[$i]);
$qty[$i] = mysqli_real_escape_string($db, $qty[$i]);
$price[$i] = mysqli_real_escape_string($db, $price[$i]);
if (count($item) >= 0 && count($item) <= 24) {
mysqli_query($db, "insert into purchase_order_history values('', '{$item[$i]}', '{$qty[$i]}', '{$price[$i]}', '', '$supplier[$i]', 'Pending')");
echo "Success";
}
else {
echo "Error";
}
}
}
?>
Basically it uses the arrays of item, qty, and price. My problem is that it doesn't insert anything at all despite no errors to the PHP. The query is:
insert into purchase_order_history values('', '{$item[$i]}', '{$qty[$i]}', '{$price[$i]}', '', '$supplier[$i]', 'Pending');
EDIT: Here's the JQuery code:
<!-- jQuery library -->
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Bootstrap js library -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
//group add limit
var maxGroup = 24;
//add more fields group
$(".addMore").click(function(){
if($('body').find('.form').length < maxGroup){
var fieldHTML = '<div
class="form">'+$(".formCopy").html()+'</div>';
$('body').find('.form:last').after(fieldHTML);
}else{
alert('Only '+maxGroup+' items are allowed.');
}
});
//remove fields group
$("body").on("click",".remove",function(){
$(this).parents(".form").remove();
});
});
</script>
Is there an error with the query itself? Or is it the array coding that causes the problem?

PHP Checkbox ordered by click and send thru post form to a news sql query on the clicked order

I have a code on page1.php where I have an array of checkbox populated with mysql data through a query. I can successfully submit the value of the checked checkbox to the page2.php. But I want to submit it according to the sequence the checkbox was checked by the user. I´ve seen that jQuery can do this, but i don´t know how and where to place the jQuery code.
My intention is to show on page2.php what the user selected, on a specific order, from the page1.php form
MODIFIED: Well , I managed to create the list and send via form . The problem now is to put a comma between the numbers . I know this must be the easiest problem to solve , but I can not yet.
The SQL Query is looking like this, for example:
SELECT * FROM emp WHERE id IN (7,9,30) ORDER BY FIELD (id,
30 9 7)
page1.php
<script type="text/javascript">
var listCheckedOptions = [];
function addToList(checkObj, outputObjID) {
//Remove from array if the element already in.
if (listCheckedOptions.indexOf(checkObj) >= 0) {
listCheckedOptions.splice(listCheckedOptions.indexOf(checkObj), 1);
}
listCheckedOptions.push(checkObj);
document.getElementById(outputObjID).value = ""; //Clean textarea
document.getElementById(outputObjID).value = listCheckedOptions.map(function (o) {
return o.value;
}).join('\r\n'); //Add to textarea
if (!checkObj.checked) checkObj.nextSibling.querySelector('span').innerHTML = '';
listCheckedOptions.forEach(function (el, i) {
var span = el.nextSibling.querySelector('span').innerHTML = i + 1;
});
return;
}
</script>
<?php
$query = "SELECT * FROM imoveis";
$result = mysql_query($query,$conn);
?>
<form action="page2.php" method="post">
<input type="submit" value="Create" id="enviarButton"/></td>
<br><br>
<table border="1">
<?
$i = 0;
echo "<tr>";
while($imovel = mysql_fetch_array($result)){
$name = $imovel['emp'];
$id = $imovel['id'];
?>
<td>
<?=$name;?><br>
<input type="checkbox" name="op_imovel[]" value="<?=$id;?>" onClick="addToList(this, 'txt1')">
</td>
<?
$i++;
if(($i % 3) == 0){
echo "</tr><tr>";
}
}
mysql_close();
?>
</table>
<br>
<input type="hidden" name="txt1" id="txt1">
</form>
page2.php
<?php
$checkbox = $_POST['op_imovel'];
$lista = $_POST['txt1'];
if (is_array($checkbox) && count($checkbox) > 0){
$res = '';
$tot = count($checkbox) - 1;
for ($y = 0; $y <= $tot; $y++) {
$res .=$checkbox[$y];
if ($y < $tot)
$res .= ",";
}
}
$query = "SELECT * FROM emp WHERE id IN ($res) ORDER BY FIELD (id, $lista)";
$result = mysql_query($query,$conn);
?>
<br>
<div align="center">
<table border="1">
<?
$i = 0;
echo "<tr>";
if (is_array($checkbox) && count($checkbox) > 0){
while($imovel = mysql_fetch_array($result)){
$name = ($imovel['emp']);
?>
<td>
<p>
<?= $name;?>
</p>
</td>
<?
$i++;
if(($i % 3) == 0){
echo "</tr><tr>";
}
}
}
?>
</div>
<? mysql_close(); ?>

INSERT a row per array object

I am in the process of creating a document association tool whereby users can associate documents to a ticket from a pre-existing list of documents.
Thanks to the help of Alberto Ponte I was able to construct the initial radio box system (originally checkbox, changed for obvious reasons) from this question: Separate out array based on array data
Now that I have the radio buttons presenting correctly I am trying to get the data inserted into a MySQL with a row for each document. Following on from this I want to have it look up the table for each object and see if there is an existing entry and update that rather than inset a duplicate entry.
Apologies in advance for the soon to be depreciated code and I will be correcting the code going forward, however that is a much bigger task than I currently have time for.
Also apologies if the code is considered messy. I'm not fantastic at PHP and not too hot on best practices. Any quick pointers are always welcome.
Display code:
<?php
include "../includes/auth.php";
include "../includes/header.php";
## Security ########################################################
if ($company_id != 1 OR $gid < 7) {
echo' <div class="pageheader">
<div class="holder">
<br /><h1>Access Denied <small> Your attempt has been logged</small></h1>
</div>
</div>
';
exit();
}
// GET Values ###################################################
$jat_id = intval($_GET['id']);
$div_id = intval($_GET['div_id']);
## Page Start ########################################################
echo '
<div class="pageheader">
<div class="holder">
<br /><h1>Clovemead Job Management Platform<small> Welcome...</small></h1>
</div>
</div>
<div class="well5" style="width:1000px !important;">
<h3>Create Document Association</h3>
<table border=1>
<tr>
<td align=center><p>Here you can associate documents to Jobs and Tasks to.</p> </td>
</tr>
</table>';
$order2 = "SELECT * FROM documents";
$result2 = mysql_query($order2);
while ($row2 = mysql_fetch_array($result2)) {
$nice_name = $row2['nice_name'];
$doc_id = $row2['id'];
}
echo '
<h3>Documents</h3>
<table border=1>
<tr><th>Document Name</th><th>Document Type</th><th>Required</th><th>Optional</th><th>Not Required</th></tr>
';
$order2 = "SELECT * FROM documents ORDER BY type_id";
$result2 = mysql_query($order2);
while ($row2 = mysql_fetch_array($result2)) {
$nice_name = $row2['nice_name'];
$doc_id = $row2['id'];
$doc_type_id = $row2['type_id'];
echo '
<tr>
<td>'.$nice_name.'</td>';
$order3 = "SELECT * FROM document_types WHERE id = '$doc_type_id'";
$result3 = mysql_query($order3);
while ($row3 = mysql_fetch_array($result3)) {
$type_name = $row3['type_name'];
echo '
<td>'.$type_name.'</td>
<form method="post" action="create-doc-assoc-exec.php">
<input type="hidden" value="'.$doc_id.'" name="doc_id">
<input type="hidden" value="'.$jat_id.'" name="jat_id">
<input type="hidden" value="'.$div_id.'" name="div_id">';
$order4 = "SELECT * FROM document_assoc WHERE doc_id = '$doc_id'";
$result400 = mysql_query($order4);
$_results = mysql_fetch_array($result400);
if (!$_results) {
echo '
<td><input type="radio" name="req0" value="2"></td>
<td><input type="radio" name="req0" value="1"></td>
<td><input type="radio" name="req0" value="0" checked ></td>';
} else {
foreach ($_results as $result400) {
$requirement = $_results['requirement'];
}
$name = "req".$doc_id;
echo '
<input type="hidden" value ="'.$name.'" name="name">
<td><input type="radio" name="'.$name.'" value="2" '; if ($requirement == 2) { echo ' checked '; } echo '></td>
<td><input type="radio" name="'.$name.'" value="1" '; if ($requirement == 1) { echo ' checked '; } echo '></td>
<td><input type="radio" name="'.$name.'" value="0" '; if ($requirement < 1) { echo ' checked '; } echo '></td>';
}
}
echo '
</tr>';
}
echo '
</table>
<input type="submit" name="submit value" value="Create Document Association" class="btn success Large"></form>';
$order2 = "SELECT * FROM divisions WHERE id = '$div_id'";
$result2 = mysql_query($order2);
while ($row2 = mysql_fetch_array($result2)) {
$dbname = $row2['division_dbname'];
$order3 = "SELECT * FROM $dbname WHERE id = '$jat_id'";
$result3 = mysql_query($order3);
while ($row3 = mysql_fetch_array($result3)) {
$type = $row3['type'];
$type2 = strtolower($type);
echo '
<input type="button" value="Back" onclick="window.location='./view-'.$type2.'.php?id='.$jat_id.''" class="btn primary Large">
';
}}
echo '
</div>';
include "../includes/footer.php";
?>
Execute Code:
<?php
include "../includes/dbconnect.php";
$name = $_POST['name'];
$name = stripslashes($name);
$name = mysql_real_escape_string($name);
$doc_id = intval($_POST['doc_id']);
$jat_id = intval($_POST['jat_id']);
$div_id = intval($_POST['div_id']);
$req = intval($_POST[$name]);
$req_blank = intval($_POST['req0']);
if ($req_blank == 0) {
$requirement = 0;
} elseif ($req_blank == 1) {
$requirement = 1;
} elseif ($req_blank == 2) {
$requirement = 2;
} elseif ($req == 0) {
$requirement = 0;
} elseif ($req == 1) {
$requirement = 1;
} elseif ($req == 2) {
$requirement = 2;
}
foreach ($doc_id as $doc_id2) {
$order = "INSERT INTO document_assoc (jat_id, dept_id, doc_id, requirement) VALUES ('$jat_id', '$div_id', '$doc_id2', '$requirement')";
$result = mysql_query($order);
$order1 = "SELECT * FROM divisions WHERE id = '$div_id'";
$result1 = mysql_query($order1);
while ($row1 = mysql_fetch_array($result1)) {
$dbname = $row1['division_dbname'];
$order2 = "SELECT * FROM $dbname WHERE id = '$jat_id'";
$result2 = mysql_query($order2);
while ($row2 = mysql_fetch_array($result2)) {
$type = $row2['type'];
$type2 = strtolower($type);
if($result){
header("location:view-$type2.php?id=$jat_id&creation=success");
} else {
header("location:view-$type2.php?id=$jat_id&creation=failed");
}
}}
}
?>
A few reference points:
$doc_id is the ID of each document which is to be passed over as an array for use in a (i believe) foreach insert
$jat_id is the ticket id documents are being associated to
$div_id is the department the ticket is associated
And the radio boxes are to decider the requirement of each document. To be passed over inline with $doc_id
What I have tried:
After a fair bit of searching - finding nothing - rechecking my terminology and searching again I managed to find the suggestion of using base64_encode(serialize()) on the arrays but I could not get this to work.

php session vars

I'm working on news archive page for my website, search over archive is done with start date, end date and news category as search parameters. Form values are stored in $_SESSION var, and then they are passed around as an array for pagination and other purposes.
My question would be how to prevent displaying search results on main archive search page if user for some reason goes again to it to make a new search.
here's the code
<?php
session_start();
if (isset($_POST['submit'])) {
//get data from the form
$archFld_1 = $_POST['archiveFld1'];
$archFld_2 = $_POST['archiveFld2'];
$archFld_3 = $_POST['archiveFld3'];
//just some check on fields
if (strlen($archFld_1) > 10) { $archFld_1 = ""; }
if (strlen($archFld_2) > 10) { $archFld_2 = ""; }
//save them as a array and store to session var
$_archValues = array($archFld_3, $archFld_1, $archFld_2);
$_SESSION['storeValues'] = $_archValues;
}
if (isset($_SESSION['storeValues'])) {
//check params for search
//set cat for query
if ($_SESSION['storeValues'][0] > 0) { $valCat = "AND newsCat=". $_SESSION['storeValues'][0] ." "; } else { $valCat = ""; }
//set date for query
if(($_SESSION['storeValues'][1] != "" ) && ($_SESSION['storeValues'][2] == "")) {
$DateStart = $_SESSION['storeValues'][1];
$valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') >= STR_TO_DATE('$DateStart', '%d-%m-%Y') ";
}
if(($_SESSION['storeValues'][2] != "") && ($_SESSION['storeValues'][1]=="")) {
$DateEnd = $_SESSION['storeValues'][2];
$valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') <= STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
}
if(($_SESSION['storeValues'][1]!="") && ($_SESSION['storeValues'][2] != "")) {
$DateStart = $_SESSION['storeValues'][1];
$DateEnd = $_SESSION['storeValues'][2];
$valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') BETWEEN STR_TO_DATE('$DateStart', '%d-%m-%Y') AND STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
}
//query string and stire it to session
$archQuery_string = $valCat.$valDate;
$_SESSION['storeQuery'] = $archQuery_string;
}
//pagination start
$page = $_GET['id'];
$perPage = 10;
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION["storeQuery"] ."ORDER BY newsId DESC");
$totalPages = mysql_num_rows($result);
if(!$page)
$page = 1;
$start = ($page - 1)*$perPage;
?>
<div id="sps_middle">
<div class="sps_cnt">
<div id="sps_middle_ly1">
<div class="sps_cnt_small">
<div class="sps_page_title"><h3><?php echo $wb_lng['txtArchiveTitle']; ?></h3></div>
<div class="sps_pages_cnt" style="padding-top: 10px; float: left; margin-bottom: 15px;">
<div class="sps_middle_col01">
<div style="float: left;">
<p>
<?php echo $wb_lng['txtArchiveInfo']; ?>
</p>
<form action="<?php $PHP_SELF; ?>" method="post" name="archiveForm" class="archiveForm">
<ul>
<li>
<input name="archiveFld1" type="text" id="archiveFld1" value="<?php echo $wb_lng['txtArhivaFld_01']; ?>" />
<input name="archiveFld2" type="text" id="archiveFld2" value="<?php echo $wb_lng['txtArhivaFld_02']; ?>" />
<select name="archiveFld3">
<option value="0"><?php echo $wb_lng['txtArhivaFld_07']; ?></option>
<option value="0" ><?php echo $wb_lng['txtArhivaFld_06']; ?></option>
<option value="1"><?php echo $wb_lng['txtArhivaFld_03']; ?></option>
<option value="2"><?php echo $wb_lng['txtArhivaFld_04']; ?></option>
<option value="3"><?php echo $wb_lng['txtArhivaFld_05']; ?></option>
</select>
</li>
<li style="float: right;">
<input name="reset" type="reset" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormReset']; ?>"/>
<input name="submit" type="submit" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormSend']; ?>"/>
</li>
</ul>
</form>
</div>
<hr />
<?php
if (#HERE GOES SOME CODE TO PERFORM THE CHECK!!!#) {
//perform db query
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION['storeQuery'] ."ORDER BY newsId DESC LIMIT $start, $perPage");
//count rows
$totalnews = mysql_num_rows($result);
$count = 1;
if($totalnews == 0) {
//no results, say to the user
echo "\t\t\t<div class=\"cil_news_text_big\">\n\t\t\t\t".$wb_lng['txtArchiveNoEntries']."\n\t\t\t</div>\n";
} else {
//we have results, yeeeeeeeeey
while($ROWnews = mysql_fetch_object($result)){
//set link extensions by the news cat
switch ($ROWnews->newsCat) {
case 1:
$newsCat_link = "news";
break;
case 2:
$newsCat_link = "statements";
break;
case 3:
$newsCat_link = "events";
break;
}
//text summary
if (strlen($ROWnews->newsShort) > 0 ) {$newsShortTxt = strip_tags($ROWnews->newsShort);
if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
} else {
$newsShortTxt = strip_tags($ROWnews->newsFull);
if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
}
$newsShortTxt = wbShorTxt($newsShortTxt, 210, "... <a title=\"".$wb_lng['txtShowMore']."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$wb_lng['txtShowMore']."...</a>");
//show news
echo "\t\t<div class=\"sps_news_list\">\n";
echo "\t\t<div class=\"sps_news_l\">\n";
echo "\t\t\t<img alt=\"\" src=\"http://".$_SERVER['HTTP_HOST']."/content/images/news/_thumb/".$ROWnews->newsImageThumb."\" />\n";
echo "\t\t</div>";
echo "\t\t<div class=\"sps_news_r\">\n";
//transliterate title
if ($lang_id==2) { $newsTitle = wbTranslit($ROWnews->newsTitle); } else { $newsTitle = $ROWnews->newsTitle; }
echo "\t\t\t<div class=\"sps_news_title\">\n\t\t\t\t<a title=\"".$newsTitle."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$newsTitle."</a>\n\t\t\t</div>\n";
echo "\t\t\t<div class=\"sps_news_date\">\n\t\t\t\t".$ROWnews->newsDate."\n\t\t\t</div>\n";
echo "\t\t\t<div class=\"sps_news_text_sh\">\n\t\t\t\t".$newsShortTxt."\n\t\t\t</div>\n";
echo "\t\t</div>";
echo "\t\t</div>";
//show <hr /> based on $count
if($totalnews != $count) { echo "\t\t\t<hr />\n"; }
$count++;
}
}
//pagination check
if($totalPages>$perPage) {
?>
<hr />
<div class="sps_pagginate">
<?PHP wbPageTurnFront($PHP_SELF."/".$lang_link."/archive/", $totalPages, $page, $perPage); ?>
</div>
<?php
}
}
?>
Any ideas?
Tnx :)
If user goes to make it a new search then you can clear the session at that time.
unset($_SESSION['storeValues']);

Categories