this program works properly i just don't know how to make this additional function work...
dbconfig.php
<?php
$db_host = "localhost";
$db_name = "testproduct";
$db_user = "root";
$db_pass = "";
try{
$db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
$db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
echo $e->getMessage();
}
?>
Product Management
Here in product management I will add the product information name,price,stock etc..
add_form.php
<?php
require_once 'dbconfig.php';
if($_POST)
{
$fname = $_POST['name'];
$lname = $_POST['actualprice'];
$contactnum = $_POST['sellprice'];
$email = $_POST['Stock'];
try{
$stmt = $db_con->prepare("INSERT INTO tblproduct(name,actualprice,sellprice,Stock) VALUES(:pname,:pactualprice,:psellprice,:pStock)");
$stmt->bindParam(":pname", $name);
$stmt->bindParam(":pactualprice", $actualprice);
$stmt->bindParam(":psellprice", $sellprice);
$stmt->bindParam(":pStock", $Stock);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
<style type="text/css">
#dis{
display:none;
}
</style>
<div id="dis">
</div>
<form method='post' id='emp-SaveForm' action="#">
<table class='table table-bordered'>
<tr>
<td>Product Name</td>
<td><input type='text' name='name' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td>Actual Price</td>
<td><input type='text' name='actualprice' class='form-control' placeholder='EX : Web Design, App Design' required></td>
</tr>
<tr>
<td>Sell Price</td>
<td><input type='text' name='sellprice' class='form-control' placeholder='EX : 180000' required></td>
</tr>
<tr>
<td>Stock</td>
<td><input type='text' name='Stock' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
</form>
index.php
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Product Name</th>
<th>Actual Price</th>
<th>Sell Price</th>
<th>Stock</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
$stmt = $db_con->prepare("SELECT * FROM tblproduct ORDER BY id DESC");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['actualprice']; ?></td>
<td><?php echo $row['sellprice']; ?></td>
<td><?php echo $row['Stock']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
Sales Management
here is the problem in sales I will add a sales record which will require a product name. the product will be selected from the table of product management including the other information for that specific product(actual price,stock,selling price) that will be show on the index
add_form.php
<?php
require_once 'dbconfig.php';
if($_POST)
{
$pname = $_POST['pname'];
$gname = $_POST['gname'];
$saledate = $_POST['saledate'];
$quantity = $_POST['quantity'];
$actualprice = $_POST['actualprice'];
$sellprice = $_POST['sellprice'];
$profit = $_POST['profit'];
$carryO = $_POST['carryO'];
$sells = $_POST['sells'];
$expense = $_POST['expense'];
try{
$stmt = $db_con->prepare("INSERT INTO tblsales(pname,gname,saledate,quantity,actualprice,sellprice,carryO,sells,expense,profit)
VALUES(:upname,:ugname,:usaledate,:uquantity,:uactualprice,:usellprice,:ucarryO,:usells,:uexpense,:uprofit)");
$stmt->bindParam(":upname", $pname);
$stmt->bindParam(":ugname", $gname);
$stmt->bindParam(":usaledate", $saledate);
$stmt->bindParam(":uquantity", $quantity);
$stmt->bindParam(":uactualprice", $actualprice);
$stmt->bindParam(":usellprice", $sellprice);
$stmt->bindParam(":ucarryO", $carryO);
$stmt->bindParam(":usells", $sells);
$stmt->bindParam(":uexpense", $expense);
$stmt->bindParam(":uprofit", $profit);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
<div id="dis">
</div>
<form method='post' id='emp-SaveForm' action="#">
<table class='table table-bordered'>
<tr>
<td>Product Name</td>
<td><input type='text'name='pname' class='form-control' required> </td>
</tr>
<tr>
<td>Guest Name</td>
<td><input type='text' name='gname' class='form-control' required> </td>
</tr>
<tr>
<td>Sale Date</td>
<td><input type='date' name='saledate' class='form-control' required></td>
</tr>
<tr>
<td>Quantity</td>
<td><input type='text' name='quantity' class='form-control' id="quantity" required></td>
</tr>
<tr>
<td>Actual Price</td>
<td>
<input type='text'name ="actualprice" id="aaprice" class='form-control' required></td>
</tr>
<tr>
<td>Selling Price</td>
<td>
<input type='text' name='sellprice' class='form-control' type = "number" id="ssprice" required></td>
</tr>
<tr>
<td>Carry Over</td>
<td><input type='text' name='carryO' class='form-control' required></td>
</tr>
<tr>
<td>Sells</td>
<td><input type='text' name='sells' class='form-control' required></td>
</tr>
<tr>
<td>Expense</td>
<td><input type='text' name='expense' class='form-control' required></td>
</tr>
<tr>
<td>Profit</td>
<td><input name='profit' class='form-control' type = "number" id="profit" required></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
index.php
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Product Name</th> //selected from product management table
<th>Sale Date</th>//(user input)
<th>Quantity</th>//(user input)
<th>Actual Price</th> //price of the selected product on the management table
<th>Selling Price</th> //price of the selected product on the management table
<th>Carry Over</th> //stock from the selected product on the management table
<th>Sells</th>//selling price of the selected product on the management table * quantity(user input)
<th>Expense</th>
<th>Profit</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
if(isset($_POST['months'])){ $months = $_POST['months']; }else { $months='';}
$stmt = $db_con->prepare("SELECT * FROM tblsales WHERE MONTH(saledate) = '".$months."' ");
//this is for the sales management for the monthly view function didn't include the my months select this post already long enough
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['pname']; ?></td>
<td><?php echo $row['saledate']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['actualprice']; ?></td>
<td><?php echo $row['sellprice']; ?></td>
<td><?php echo $row['carryO']?></td>
<td><?php echo $row['sells']?></td>
<td><?php echo $row['expense']?></td>
<td><?php echo $row['profit']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
Better way by using ajax for this case.
$.ajax({
url: "data.php",//file wich has query select to db table
data: {id:theid},//describe your data here
dataType: 'json',// type of data that will you get (JSON/HTML).
type: 'POST',//sending type (POST/GET)
success: function(data) {
showTable();
}
});
Related
I want to display the invoice bill for each customer when admin clicks on view bill button for that customer. Also I want to display all the newspaper details in a single invoice when customer name is same.I have included the relevant code and database snapshots.
c_details.php
<?php
session_start();
include_once("connect.php");
$query="SELECT * FROM sub_details";
$result=mysqli_query($conn,$query);
?>
<table align="center">
<h3 style="color: black; font-weight: bold; text-align: center;">
Subscription details</h3><br>
<tr>
<th style="text-align: center;">Id</th>
<th style="text-align: center;">Name</th>
<th style="text-align: center; width: 900px">Newspaper</th>
<th style="text-align: center;">Duration</th>
<th style="text-align: center;">Price</th>
<th style="text-align: center; width: 800px">Subscription date</th>
<th style="text-align: center;">Remaining Days</th>
<th style="text-align: center;">Bill</th>
</tr>
<?php while($rows=mysqli_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['newspaper']; ?></td>
<td><?php echo $rows['duration']; ?></td>
<td><?php echo $rows['price']; ?></td>
<td><?php echo $rows['sdate']; ?></td>
<?php echo var_dump($result->fetch_all(MYSQLI_ASSOC));
$date1=date_create();
$date2=date_create($rows['edate']);
$interval=date_diff($date2,$date1)->format("%a days");
?>
<td><?php echo $interval; ?></td>
<td>
<form action="invoice.php" method="GET">
<?php $invoiceId = $rows['name']; ?>
<button type="submit" onclick= "window.open('invoice.php?name= '<?php echo
$rows['name']; ?>)" class="btn btn-primary btn-lg" value="submit" >
View bill</button></td>
</form>
</tr>
<?php } ?>
</table>
invoice.php
<?php
include_once("connect.php");
$invoiceId = isset($_GET['name']) ? $_GET['name'] : null;
if($invoiceId) {
$query = "SELECT * FROM sub_details WHERE name = ? limit 1";
$result = mysqli_query($conn,$query);
?>
<?php while($rows=mysqli_fetch_assoc($result)) {
?>
<form style="text-align: left;margin-left: 30px" class="register-form" id="register-form">
<div class="form-group"> Bill no: <input type="text" name="id" value="<?php echo $rows['id']; ?>"></div><br>
<div class="form-group">Name: <input type="text" name="name" value="<?php echo $rows['name']; ?>"></div><br>
<div class="form-group">Address: <input type="text" name="address" value="<?php echo $rows['address']; ?>"></div><br><br>
</form>
</th>
</tr>
<td>
<table cellpadding="5px" cellspacing="6px" style="width: 75%; border-radius:20px;">
<tr>
<th>Newspaper</th>
<th >Duration</th>
<th >Price</th>
</tr>
<tr>
<td ><?php echo $rows['newspaper']; ?></td>
<td><?php echo $rows['duration']; ?></td>
<td><?php echo $rows['price']; ?></td>
</tr>
<tr>
<td>DELIVERY CHARGES</td>
<td colspan="3" style="padding-right:60px;text-align: right;">50</td>
</tr>
<tr>
<th>Total</th>
<?php
$t_price=$rows['price']+ 50; ?>
<th colspan="3" style="text-align: right;padding-right: 55px"><?php echo $t_price; ?></th>
</tr>
<tr>
<th colspan="4" >
<br><br><br><br><br><br><br>
</th>
</tr>
</table>
</td>
<tr>
<th colspan="4" style="border-top-color: #ffff4d">
<p style="text-align: left;">Note: Clients are requested to pay the bill before 5th of every month.</p>
</th>
</tr>
<?php } ?>
</table>
Database screenshots
First, you should pass the invoice ID for each record in c_details.php so that you can identify them later:
<button type="submit" onclick= "window.open('invoice.php?id='<?php echo $rows['id']; ?>)" class="btn btn-primary btn-lg" value="submit" >View bill</button>
It will produce URLs like invoice.php?id=<id>, where <id> is the ID for each record in the database. So, for example, a record with the ID 102 will be invoice.php?id=102.
On invoice.php, you can retrieve the ID with $_GET['id']. You should adjust your query to fetch the data for the given invoice:
$invoiceId = isset($_GET['id']) ? $_GET['id'] : null;
if($invoiceId) {
$query = $conn->prepare("SELECT * FROM sub_details, signup_c WHERE id = ? limit 1";
$query->bind_param('s', $invoiceId);
$query->execute();
$result = $query->get_result();
}
If you're using PHP 7.0 or later, you can simplify your code using the null coalescing operator:
$invoiceId = $_GET['id'] ?? null;
I strongly recommend you to learn about how to prevent SQL injections in PHP.
I am facing a unknown problem while I go insert data.Some data getting inserted in same table n same column but except one.
The following is my code.
<html>
<body>
<?php
include("index.php");
?>
<form action="addcenter.php" method="post">
<table align="center" border="9" width="600">
<tr>
<td align="center" colspan="5" bgcolor="yellow">
<h1>Add Your Center Details</h1></td>
</tr>
<tr>
<th>District Name</th>
<td><input type="text" name="district"></td>
</tr>
<tr>
<th>Phone No.</th>
<td><input type="text" name="phone"></td>
</tr>
<tr>
<th>Person's Name</th>
<td><input type="text" name="person"></td>
</tr>
<tr>
<th>Designation</th>
<td><input type="text" name="designation"></td>
</tr>
<tr>
<td align="center" colspan="5"><input type="submit" name="submit"
value="submit"></td>
</tr>
</table>
</form>
<?php
include("includes/connect.php");
if(isset($_POST['submit']))
{
$district=$_POST['district'];
$phone=$_POST['phone'];
$person=$_POST['person'];
$designation=$_POST['designation'];
if($district=='' or $phone=='' or $person=='' or $designation='')
{
echo"<script> alert('Please fill the fiels')</script> ";
exit();
}
$query="insert into centers (District,Phone,ContactPerson,Designation)
values('$district','$phone','$person','$designation') ";
if(mysql_query($query))
{
echo"<center><h1>Details Successfully added to your database</h1>
</center> ";
}
}
?>
<table width=" 900" align="center" border="3">
<tr>
<td align="center" colspan="9" bgcolor="orange"><h1>View all
Centers</h1></td>
</tr>
<tr align="center">
<th>SL No.</th>
<th>District</th>
<th>Phone No</th>
<th>Contact Person</th>
<th>Designation</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php
$query="select * from centers";
$run=mysql_query($query);
$i=1;
while($row=(mysql_fetch_array($run)))
{
$center_id=$row['center_id'];
$district=$row['District'];
$phone=$row['Phone'];
$contact_person=$row['ContactPerson'];
$designation=$row['Designation'];
?>
<tr align="center">
<td><?php echo $i++ ;?></td>
<td><?php echo $district;?></td>
<td><?php echo $phone ;?></td>
<td><?php echo $contact_person ;?></td>
<td><?php echo $designation ;?></td>
<td>Edit
</td>
<td><input type="button" onclick="deleteme1(<?php echo $center_id ?>)"
name="delete" value="Delete"></td>
</tr>
<script language="javascript">
function deleteme1(delid1)
{
if(confirm("are u sure"))
{
window.location.href='deletecenter.php?del_id1='+delid1+'';
return true;
}
}
</script>
<?php } ?>
</table>
</body>
</html>
The problem is that when I going to insert the Contactperson,district,designation and phone no.Then only the data of Contactperson,district and phone no get inserted but not the designation..I dont know why this is happening even the coding is also right..Please help me. Thankyou
Your "if" statement is assigning '' to $designation. Use '==' for comparison.
if($district=='' or $phone=='' or $person=='' or $designation**=**'')
The if statement says, "if $district is '' or $phone is '' or $person is '' or 'I can assign nothing to $designation (which always succeeds)' - at which point you have successfully assigned '' to $designation. The if statement finishes and you insert '' into designation.
I'm retreiving the "In Stock" data using MySQL
<table class="table table-striped table-bordered table-hover results table-fixed">
<thead>
<tr>
<th class="text-center">#</th>
<th>Product Name</th>
<th>Description</th>
<th>Price</th>
<th>In Stock</th>
<th style="width: 20%">Quantity</th>
</tr>
<tr class="warning no-result">
<td colspan="8"><i class="fa fa-warning"></i> No Product Found</td>
</tr>
</thead>
<tbody>
<?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'];
$description = $row['description'];
$product_quantity = $row['quantity'];
$product_price = $row['sell_price'];
?>
<tr>
<td class="text-center"><?php echo $product_id; ?>
<input type="hidden" name="product_id[]" value="<?php echo $product_id; ?>">
</td>
<td><?php echo $product_name; ?></td>
<td><?php echo $description; ?></td>
<td><?php echo $product_price; ?></td>
<td><input type="number" value="<?php echo $product_quantity; ?>" id="qtyResult" disabled></td>
<td><input type="number" name="qtyBuy[]" id="qtyBuy" onkeyup="updateStock()"></td>
</tr>
<?php } ?>
</tbody>
</table>
I want to update the In Stock field automatically when I type a number on the quantity field.
The "San Mig Light's" stock is 500 but when I type a number on quantity field, the stock changes to the last record on the table which is 45.
The rest of the row doesn't also work except for the first one.
Here is my jQuery script.
<script>
function updateStock() {
var inputQty = $('#qtyBuy').val();
var inStock = "<?php echo $product_quantity; ?>"
$('#qtyResult').val(inStock - inputQty);
}
</script>
Table
Try to pass to your function the this and event keywords like:
<td><input type="number" name="qtyBuy[]" id="qtyBuy" onkeyup="updateStock(this, event)"></td>
Because the ID must be unique, try to appent a number like: qtyBuy1, qtyBuy2...
And to select these fields you can: find('input[id^="qtyResult"]') : select input field where the id starts with the string "qtyResult".
So, in your updateStock you can use the parameters to refers to the current values like:
function updateStock(obj, event) {
var inputQty = obj.value;
var inStock = "<?php echo $product_quantity; ?>";
$(obj).closest('tr').find('input[id^="qtyResult"]').val(inStock - inputQty);
}
The snippet:
function updateStock(obj, event) {
var inputQty = obj.value;
var inStock = $(obj).closest('tr').find('input[id^="qtyResult"]').val();
var av = $(obj).closest('tr').find('input[id^="qtyResult"]').data('savedValue');
if (av == undefined) {
$(obj).closest('tr').find('input[id^="qtyResult"]').data('savedValue', inStock);
av = inStock;
}
inStock = av;
console.log(av + ' / ' + inStock + ' / ' + inputQty);
$(obj).closest('tr').find('input[id^="qtyResult"]').val(inStock - inputQty);
}
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<table class="table table-striped table-bordered table-hover results table-fixed">
<thead>
<tr>
<th class="text-center">#</th>
<th>Product Name</th>
<th>Description</th>
<th>Price</th>
<th>In Stock</th>
<th style="width: 20%">Quantity</th>
</tr>
<tr class="warning no-result">
<td colspan="8"><i class="fa fa-warning"></i> No Product Found</td>
</tr>
</thead>
<tbody>
<tr>
<td class="text-center">product_id1
<input type="hidden" name="product_id[]" value="1">
</td>
<td>product name1</td>
<td>description1</td>
<td>product_price1</td>
<td><input type="number" value="1" id="qtyResult1" disabled></td>
<td><input type="number" name="qtyBuy[]" id="qtyBuy1" onkeyup="updateStock(this, event)"></td>
</tr>
<tr>
<td class="text-center">product_id2
<input type="hidden" name="product_id[]" value="<?php echo $product_id; ?>">
</td>
<td>product_name2</td>
<td>description2</td>
<td>product_price2</td>
<td><input type="number" value="1" id="qtyResult2" disabled></td>
<td><input type="number" name="qtyBuy[]" id="qtyBuy2" onkeyup="updateStock(this, event)"></td>
</tr>
</tbody>
</table>
jQuery 3.4.1
Specify this in your js script to get the correct row.
$('.myclickedclass').click(function() {
var id=$(this).data("mydataid"); // This is the most important line
$.ajax({
url:"myserverfile.php",
method:"POST",
data:{id:id},
dataType:"text",
success:function(data) {
// Whatever
}
});
});
<?php
include_once "library/inc.sesadmin.php";
include_once "library/inc.library.php";
include_once "mhsfunc.php";
$filterSQL = "";
if(isset($_POST['btnSubmit'])) {
$txtNim = trim($_POST['txtNim']);
$txtNama = trim($_POST['txtNama']);
$cmbProdi = trim($_POST['cmbProdi']);
$txtSmt = trim($_POST['txtSmt']);
$cmbSmt = trim($_POST['cmbSmt']);
if($cmbSmt<>""){
$filterSQL = "WHERE khs.nim='$txtNim' AND khs.smt='$cmbSmt'";
}else {
$filterSQL = "WHERE khs.nim='$txtNim'";
}
} else {
$filterSQL = "WHERE khs.nim='zzz'";
}
#tampilkan hasil isian di form
$dataNim =isset($_POST['txtNim']) ? $_POST['txtNim'] : '';
$dataNama =isset($_POST['txtNama']) ? $_POST['txtNama'] : '';
$dataProdi =isset($_POST['cmbProdi']) ? $_POST['cmbProdi'] : '';
$dataSmtMhs =isset($_POST['txtSmt']) ? $_POST['txtSmt'] : '';
$dataSmtKrs =isset($_POST['cmbSmt']) ? $_POST['cmbSmt'] : '';
# FOR PAGING (PEMBAGIAN HALAMAN)
$baris = 50;
$hal = isset($_GET['hal']) ? $_GET['hal'] : 1;
$pageSql = "SELECT * FROM khs $filterSQL";
$pageQry = mysql_query($pageSql, $koneksidb) or die ("error paging: ".mysql_error());
$jumlah = mysql_num_rows($pageQry);
$maks = ceil($jumlah/$baris);
$mulai = $baris * ($hal-1);
$jmlsks = 0;
$jmlbobot = 0;
$ipk = 0;
?>
<table width="800" border="0" cellpadding="2" cellspacing="0" class="table-border">
<tr>
<td colspan="3" align="right"><h1><b>DATA KRS MAHASISWA </b></h1></td>
</tr>
<tr>
<td colspan="3">
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="form1" target="_self">
<table class="table-list" width="1000" border="0" cellpadding="2" cellspacing="1" >
<tr>
<td colspan="3" style="font-size:20px; font-family:Cambria" bgcolor="#F5F5F5"><b>FILTER DATA</b></td>
</tr>
<tr>
<td width="169"><b>NIM Mahasiswa</b></td>
<td width="5"><b>:</b></td>
<td width="260"><input name="txtNim" type="text" id="txtNim" value="<?php echo $dataNim; ?>" size="15" maxlength="12" /></td>
</tr>
<tr>
<td><b>Nama Mahasiswa</b></td>
<td><b>:</b></td>
<td><input name="txtNama" type="text" id="txtNama" value="<?php echo $dataNama; ?>" size="40" maxlength="40" /></td>
</tr>
<tr>
<td><b>Program Studi</b></td>
<td><b>:</b></td>
<td><select name="cmbProdi" id="cmbProdi">
<option value="KOSONG">....</option>
<?php
$dataSql = "SELECT * FROM prodi ORDER BY kode";
$dataQry = mysql_query($dataSql, $koneksidb) or die ("Gagal Query".mysql_error());
while ($dataRow = mysql_fetch_array($dataQry)) {
if ($dataRow['kode'] == $cmbProdi) {
$cek = " selected";
} else { $cek=""; }
echo "<option value='$dataRow[kode]' $cek> [$dataRow[kode]] $dataRow[nama]</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><b>Semester Mahasiswa</b></td>
<td><b>:</b></td>
<td><input name="txtSmt" type="text" id="txtSmt" value="<?php echo $dataSmtMhs; ?>" size="3" maxlength="1" /></td>
</tr>
<tr>
<td><b>Semester KRS</b></td>
<td><b>:</b></td>
<td><select name="cmbSmt" id="cmbSmt">
<option value="">ALL</option>
<?php
$pilihan = array("1", "2", "3", "4", "5","6");
foreach ($pilihan as $semester) {
if ($dataSmtKrs==$semester) {
$cek="selected";
} else { $cek = "";}
echo "<option value='$semester' $cek>$semester</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input name="btnSubmit" type="submit" value=" Submit" id="btnSubmit" /></td>
</tr>
</table>
</form>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">
<table class="table-list" width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td colspan="5"><img src="images/btn_add_data.png" height="30" border="0" /></td>
</tr>
<tr>
<td width="28" align="center" bgcolor="#F5F5F5"><b>No</b></td>
<td width="63" bgcolor="#F5F5F5"><b>NIM</b></td>
<td width="53" bgcolor="#F5F5F5"><b>KDMK</b></td>
<td width="368" bgcolor="#F5F5F5"><b>NAMA MK</b></td>
<td width="35" bgcolor="#F5F5F5"><b>SMT</b></td>
<td width="30" bgcolor="#F5F5F5"><b>SKS</b></td>
<td width="26" bgcolor="#F5F5F5"><b>TM</b></td>
<td width="21" bgcolor="#F5F5F5"><b>PR</b></td>
<td width="19" bgcolor="#F5F5F5"><b>LP</b></td>
<td width="252" bgcolor="#F5F5F5"><b>DOSEN (NIDN/NAMA)</b></td>
<td align="center" bgcolor="#CCCCCC"><b>Tools</b></td>
</tr>
<?php
$mySql = "SELECT khs.id_khs, khs.nim, khs.kdmk, khs.nmmk, khs.smt, mtkul.sks, mtkul.tm, mtkul.pr, mtkul.lp,mtkul.nodos
FROM khs
INNER JOIN mtkul
ON khs.tahun=mtkul.tahun AND khs.prodi=mtkul.prodi AND khs.smt=mtkul.smt AND khs.kdmk=mtkul.kode $filterSQL
ORDER BY khs.smt, khs.kdmk LIMIT $mulai, $baris";
$myQry = mysql_query($mySql, $koneksidb) or die ("Query salah : ".mysql_error());
$nomor = $mulai;
while ($myData = mysql_fetch_array($myQry)) {
$nomor++;
$nidn = $myData['nodos'];
$Kode = $myData['id_khs'];
$jmlsks = $jmlsks+$myData['sks'];
$qryDosen = "SELECT * from dosen WHERE nidn=$nidn";
$qryCek = mysql_query($qryDosen, $koneksidb) or die ("Eror Query".mysql_error());
$myData2 = mysql_fetch_assoc($qryCek);
if(mysql_num_rows($qryCek)>=1){
$namaDosen=$myData2['nama'];
} else {$namaDosen=$nidn;}
// Gradasi warna baris
if($nomor%2==1) { $warna="#FFFFFF"; } else {$warna="#F5F5F5";}
?>
<tr bgcolor="<?php echo $warna; ?>">
<td align="center"><?php echo $nomor; ?></td>
<td><?php echo $myData['nim']; ?></td>
<td><?php echo $myData['kdmk']; ?></td>
<td><?php echo $myData['nmmk']; ?></td>
<td align="center"><?php echo $myData['smt']; ?></td>
<td align="center"><?php echo $myData['sks']; ?></td>
<td><?php echo $myData['tm']; ?></td>
<td><?php echo $myData['pr']; ?></td>
<td><?php echo $myData['lp']; ?></td>
<td><?php echo $namaDosen ?></td>
<td width="56" align="center">Delete</td>
//here is the KRS-Delete.php
<?php
include_once "library/inc.sesadmin.php";
// Get From URL
if(empty($_GET['Kode'])){
echo "<b>Data yang dihapus tidak ada</b>";
}
else {
$Kode = $_GET['Kode'];
$mySql = "DELETE FROM khs WHERE id_khs='$Kode'";
$myQry = mysql_query($mySql, $koneksidb) or die ("Eror hapus data".mysql_error());
if (mysql_affected_rows() > 0) {
header('location: ' .$_GET['Kode']);
echo "<script type=\"text/javascript\">".
"alert('Data Berhasil Di Hapus');".
"</script>";
echo "<meta http-equiv='refresh' content='0; url=?open=KRS-Data'>";
} else {
echo "Data tidak ditemukan !! <br><br>";
}
My Problem is that when I successfully delete a row, I want my page to go back showing the previous table shown, minus the row that I have already deleted with the exact same page number. What I need to parse into and out of KRS-Delete.php
When building UI pages that involve multiple steps, I prefer to put all steps in the same PHP file. I start with $foo = #$_GET['foo']; if ($foo) DoFoo(); to see if this call needs to do the "foo" step (such as doing the DELETE). After DoFoo(), I usually fall into the main code, which presents the UI page identical to (or similar to) the original page.
In addition to avoiding navigation problem you mentioned, it allows me to have 'all' the stuff for this UI in one file. Often there is a lot of common code, too.
Good day. Im trying to have some functionality on my project, but im stuck with this.
I want to display my database depending on what the user select
Here is my html code:
<table>
<tr><td>Select Request Status:</td>
<td><select class="form-control" name="status" style="width:200px;">
<option value="1">Pending Request</option>
<option value ="2">Requests On-Process</option>
<option value="3">Unassigned Requests</option>
<option>All Requests</option>
</select></td>
</tr>
</table>
And here is my php code:
if ($status = $_SESSION['status'] == 'Pending Request')
{
$query = "select * from tblrequest where status='Pending Request'";
$request = mysql_query($query)or die(mysql_error());?>
<table class="table">
<tr>
<th>Request ID</th>
<th>Requestor</th>
<th>Department</th>
<th>Category</th>
<th>Assigned to</th>
<th>Status</th>
<th>Created Date</th>
<th>Created Time</th>
</tr>
<?php while($row = mysql_fetch_array($request)){
?>
<tbody class="table table-hover">
<tr>
<td style="width:100px;"><?php echo $row['RequestNumber']; ?></td>
<td style="width:100px;"><?php echo $row['Requestor']; ?></td>
<td style="width:100px;"><?php echo $row['Department']; ?></td>
<td style="width:50px;"><?php echo $row['category']; ?></td>
<td style="width:100px;"><?php echo $row['AssignedTo']; ?></td>
<td style="width:100px;"><?php echo $row['status']; ?></td>
<td style="width:100px;"><?php echo $row['DateRequested']; ?></td>
<td style="width:100px;"><?php echo $row['TimeRequested']; ?></td>
</tr>
</tbody>
<?php
}
}?>
Im a newbie to php so please help me.
Can you try this,
HTML:
<form method="post">
<table>
<tr><td>Select Request Status:</td>
<td>
<?php $Statuses = array("0"=>"All Requests", "1"=>"Pending Request", "2"=>"Requests On-Process", "3"=>"Unassigned Requests" );?>
<select class="form-control" name="status" style="width:200px;" onchange="this.form.submit();">
<?php foreach($Statuses as $key=>$status):?>
<?php
$selected ="";
$statusPost = $_POST['status'];
if($key == $statusPost): $selected =" selected"; endif;
?>
<option value="<?php echo $key;?>" <?php echo $selected;?>><?php echo $status;?></option>
<?php endforeach;?>
</select></td>
</tr>
</table>
</form>
PHP:
if (isset($_POST['status'])){
$status= $_POST['status'];
$Where ='';
if($status!='0'){
$Where =" where status='".$Statuses[$status]."' ;
}
}
$query = "select * from tblrequest $Where";
$request = mysql_query($query)or die(mysql_error());?>
<table class="table">
<tr>
<th>Request ID</th>
<th>Requestor</th>
<th>Department</th>
<th>Category</th>
<th>Assigned to</th>
<th>Status</th>
<th>Created Date</th>
<th>Created Time</th>
</tr>
<?php while($row = mysql_fetch_array($request)){
?>
<tbody class="table table-hover">
<tr>
<td style="width:100px;"><?php echo $row['RequestNumber']; ?></td>
<td style="width:100px;"><?php echo $row['Requestor']; ?></td>
<td style="width:100px;"><?php echo $row['Department']; ?></td>
<td style="width:50px;"><?php echo $row['category']; ?></td>
<td style="width:100px;"><?php echo $row['AssignedTo']; ?></td>
<td style="width:100px;"><?php echo $row['status']; ?></td>
<td style="width:100px;"><?php echo $row['DateRequested']; ?></td>
<td style="width:100px;"><?php echo $row['TimeRequested']; ?></td>
</tr>
</tbody>
<?php
}
?>
put select dropdown in a form with id,action,method etc.
give id to a select element(say "mySelect")
Now, in jquery,
$("#mySelect").on("change",function(){
if($("#mySelect").val() != ""))
{
$("#form1").submit();
}
})