How to display count data accumulation and residual data in table automatically? - php

I have a problem, I use the straight-line method when displaying the accumulation and residue. I wonder how can I use php to automate the calculation.
This is the form used to submit the data:
<h1>Penyusutan</h1>
<table>
<form action="deprecalc.php" method="post">
<label>Nominal : </label>
<input type="text" name="nominal"><br>
<label>Lama Depresiasi : </label>
<input type="text" name="depresiasi"><br>
<label>Awal : </label>
<input type="text" name="awal"><br>
<label>Akhir : </label>
<input type="text" name="akhir"><br>
<label>Residu Aset : </label>
<input type="text" name="residu"><br>
<input type="submit">
</form>
</table>
This is the php handling:
<?php
$nominal = $_POST['nominal'];
$depresiasi = $_POST['depresiasi'];
$awal = $_POST['awal'];
$akhir = $_POST['akhir'];
$residu = $_POST['residu'];
?>
<h2>Nominal : <?php echo $nominal;?></h2></br>
<h2>Despresiasi : <?php echo $depresiasi;?></h2></br>
<table id="values">
<tr>
<th>Nominal</th>
<th>Tahun</th>
<th>Umur</th>
<th>Akumulasi</th>
<th>Residu</th>
</tr>
<?php
$no = 1;
$years = date('Y');
for ($i=0; $i < $depresiasi ; $i++) {
$rumus = ($nominal - $residu) / $depresiasi;
$rumusResidu = ($nominal - $rumus);
?>
<tr>
<?php echo "<td>".$nominal."</td>" ?>
<?php echo "<td>".$years++."</td>" ?>
<?php echo "<td>".$no++."</td>" ?>
<?php echo "<td>".$rumus."</td>" ?>
<?php echo "<td>".$rumusResidu."</td>" ?>
</tr>
<?php } ?>
</table>
And the result I have made:
Attached with the desired result: How do I achieve this? Thanks

Related

Input Fibonacci in table generate PHP

Hello i have the following script to generate a table
<?php error_reporting(null); ?>
<form action="" method="POST" autocomplete="off">
Row<br>
<input type="text" value="<?php echo $_POST['row'] ?>" name="row"><br/>
Kolom<br>
<input type="text" value="<?php echo $_POST['kolom'] ?>" name="kolom">
<input type="hidden" name="aksi" value="gen">
<br/><br/>
<input type="submit" value="Submit">
</form>
<?php
if($_POST['aksi']=="gen"){
echo "<table border=1>";
for ($i=1; $i<=$_POST['row']; $i++) { ?>
<tr>
<?PHP for ($y=1; $y<=$_POST['kolom']; $y++) { ?>
<td>Data</td>
<?php } ?>
</tr>
<?php }
echo "</table>";
}
?>
And i have a script to generate a fibonacci number
<?php
$first=0;
$second=1;
echo "$first $second";
for ($i=0; $i<10; $i++)
{
$third = $second + $first;
echo " $third";
$first = $second;
$second = $third;
}
?>
I want to join the 2 scripts.
when i a generate a table, Fibonacci needs to be placed inside the table, i don't know how to solve this.
This Result like this
This should do the trick. Cannot test so if there are any typos keep them :)
<?php error_reporting(null); ?>
<form action="" method="POST" autocomplete="off">
Row<br>
<input type="text" value="<?php echo $_POST['row'] ?>" name="row"><br/>
Kolom<br>
<input type="text" value="<?php echo $_POST['kolom'] ?>" name="kolom">
<input type="hidden" name="aksi" value="gen">
<br/><br/>
<input type="submit" value="Submit">
</form>
<?php
if($_POST['aksi']=="gen"){
$first=0;
$second=1;
?>
<table border=1>
<?php
for ($i=0; $i<$_POST['row']; $i++) {
?>
<tr>
<?PHP
for ($y=0; $y<$_POST['kolom']; $y++) {
/* first two should be 0 and 1*/
if($y < 2 && $i == 0) {
?>
<td>0</td>
<td>1</td>
<?php
$y += 2;
} else {
$third = $second + $first;
?>
<td><?php echo($third); ?></td>
<?php
$first = $second;
$second = $third;
}
}
?>
</tr>
<?php
}
}
?>
</table>

POST $_SESSION variable using HTML

hope you are all doing well. I'm not too sure on how I worded the title so I'm sorry for that.
I have this code:
<form method="POST" action="checkoutManager.php" name="submitOrder">
<?php
if(isset($_SESSION["cart_item"])) {
$item_total = 0;
$total;
foreach ($_SESSION["cart_item"] as $item) {
$item_total += (($item["price"]-$item["discount"])*$item["quantity"]);
$total = $total + $item_total;
?>
<tr>
<td class="product-name">
<?php echo $item["name"]; ?> <strong class="product-qty"> × <?php echo $item["quantity"]; ?></strong>
</td>
<td class="product-total">
<span class="amount"><?php echo "$".$item_total; ?></span>
</td>
</tr>
<?php
$item_total = 0;
}
}
?>
<input type="submit" name="btnSubmitOrder" value="Submit Order">
</form>
How would I go about submitting all the $_SESSION items in using form tag. I have tried submitting as an array but failed. All help appreciated. Thanks in advance
why don't you create hidden elements like
<input type="hidden" name="total" value="<?php echo $total; ?>">
and anything you need use hidden input field and you can access them after the submit button is clicked by using $_POST in your checkoutManager.php
UPDATE
simply you can process all the fields in checkoutManager.php using session, you dont need any form to be submitted. create a link to checkoutManager.php and do all the calculations there
Try below code.
In this code I have added one hideen count field.
By using count u can use for loop after submit.
I display only one input for name but u can add multiple inputs inside for loop of form.
I also concated $i variables, so all input names are different as name1, name2,... U can use it on submit as $_POST['name'.$i] after submit.
<form method="POST" action="checkoutManager.php" name="submitOrder">
<?php
<input type="hidden" name="count" value="<?php echo count($_SESSION["cart_item"]); ?>">
$i=0;
foreach ($_SESSION["cart_item"] as $item)
{
?>
<input type="text" name="input_name<?php echo $i; ?>" value="<?php echo $item['name']; ?>" />
<?php
$i++;
}
?>
<input type="submit" name="btnSubmitOrder" value="Submit Order">
</form>
You need to add input fields in foreach loop for all your items that are coming in $_SESSION["cart_item"]. After submission, you need to use foreach again for inserting all your items in your temp table one by one.
Update your code like below:
<form method="POST" action="checkoutManager.php" name="submitOrder">
<?php
if(isset($_SESSION["cart_item"])) {
$item_total = 0;
$total = 0;
foreach ($_SESSION["cart_item"] as $item) {
$item_total +=
(($item["price"]-$item["discount"])*$item["quantity"]);
$total = $total + $item_total;
?>
<input type="hidden" name="price[]" value="<?php echo $item["price"]; ?>">
<input type="hidden" name="name[]" value="<?php echo $item["name"]; ?>">
<input type="hidden" name="discount[]" value="<?php echo
$item["discount"]; ?>">
<input type="hidden" name="quantity[]" value="<?php echo
$item["quantity"]; ?>">
<tr>
<td class="product-name">
<?php echo $item["name"]; ?> <strong class="product-qty"> × <?php
echo $item["quantity"]; ?></strong>
</td>
<td class="product-total">
<span class="amount"><?php echo "$".$item_total; ?></span>
</td>
</tr>
<?php
$item_total = 0;
}
}
?>
<input type="submit" name="btnSubmitOrder" value="Submit Order">
</form>
And you can access all your input fields after submission in the below way.
foreach($_POST['name'] as $key => $val){
echo $_POST['name'][$key];
echo $_POST['price'][$key];
echo $_POST['discount'][$key];
echo $_POST['quantity'][$key];
}
Hope it helps!

Getting data from database and update for a particular record in php

I'm fetching the data from database for a particular record using email id in the hidden field.
If I try to add as input type="text" it is not working for me, can any one check this.
Here is my code.
Index.php:
<?php
session_start();
$username = $_SESSION['username'];
if($username) {
?>
<h3> Welcome <?php echo $username; ?></h3>
<?php
} else {
echo "no";
}
?>
<html>
<body>
<table class="table table-hover">
<form action="personalinfo.php" METHOD="POST">
<input type="hidden" value="<?php echo $username;?>" name="email">
<tr>
<th><label for="first_name">Name</label></th>
</tr>
<?php
include "personalinfo.php";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
<input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
echo "</tr>";
}
echo "</table>";
?>
</form>
</body>
</html>
personalinfo.php :
<?php
$connection = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db("accountant", $connection);
$result = mysql_query("SELECT * FROM registered where email='$username'");
?>
In index.php, if I use like this in while condition 'first_name';?> name="first_name"/> so that I can update the record but if i remove this
echo "<td>" . $row['first_name'] . "</td>";
and if I add like this instead of that echo
<?php echo $row->first_name;?>
it gives error as
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\index\index.php on line 44
You have an error in your syntax try using this code
<?php
session_start();
?>
<?php
$username = $_SESSION['username'];
if($username) {
?>
<h3> Welcome <?php echo $username; ?></h3>
<?php
} else {
echo "no";
}
?>
<html>
<body>
<table class="table table-hover">
<form action="personalinfo.php" METHOD="POST">
<input type="hidden" value="<?php echo $username;?>" name="email">
<tr>
<th><label for="first_name">Name</label></th>
</tr>
<tr>
<?php
include "personalinfo.php";
while($row = mysql_fetch_array($result)) {
?>
<tr>
<input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
</tr>
<?php }?>
</table>
</form>
</body>
</html>
You are getting error because there's a HTML tag in php code.
This line has issue, as it was written in PHP code:
<input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
Try replacing the code with this :
<?php
include "personalinfo.php";
while($row = mysql_fetch_array($result)) {
?>
<tr>
<input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
<!-- //or this can be used <input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
-->
</tr>
<?php
}
?>
</table>

how to get the date and time html and php

I am working on a school management system. I am facing a problem while writing backend code for datesheet. I want to perform an action like admin will be able to create datesheet for student a datesheet form is given below:
<br />
<br />
<br />
<form method="post" action="adddatesheet.php" >
<table>
<th colspan="4"><h1>CREATE DATESHEET</h1></th>
<?php require_once '../lib/config/Database.php';
$DbCon = new Database();
$DbCon->connect();
$Class = $DbCon->select("class");
?>
<tr><td>Session:</td><td><input type="text" name="session" ></td></tr>
<tr><td>Class :</td><td>
<select name="class_id">
<?php while($class = $Class->fetch_array()){ ?>
<option value="<?php echo $class[0]; ?>"><?php echo $class[1]; ?></option>
<?php } ?>
</select>
</td></tr>
<?php for($i=0; $i<8; $i++){
$Subject = $DbCon->select("subject");
?>
<tr>
<td>Subject :</td><td>
<select name="<?php echo $i; ?>">
<?php while($subject = $Subject->fetch_array()){ ?>
<option value="<?php echo $subject[0]; ?>"><?php echo $subject[1]; 1?></option>
<?php } ?>
</select>
</td>
<td>Date :</td><td><input type="date" name="date<?php echo $i; ?>" /></td>
<td>Time :</td><td><input type="time" name="time<?php echo $i; ?>" /></td></tr>
<?php } ?>
<tr><td colspan="2" align="center"><input type="submit" name="submit-datesheet" value="Save" /></td></tr>
</table>
</form>
i want to get the selected date and time with subjects. but i am unable to do. Here is a code to check the data
<?php
if(isset($_POST['submit-datesheet'])){
for($i=0; $i<8; $i++){
echo $_POST['session']."<br />";
echo $_POST[$i]."<br />";
echo $_POST['class_id']."<br />";
echo $_POST['date']."<br />";
echo $_POST['time']."<br />";
}
}else{
header("LOCATION: index.php");
}
?>
it doesn't return the selected date and time.
That's because the name of your date and time fields is dynamic (name="date<?php echo $i; ?>"), but your retrieval doesn't take this into account.
You should be using
for($i=0; $i<8; $i++){
echo $_POST['date'.$i]."<br />";
echo $_POST['time'.$i]."<br />";
}
instead.

On submit echo td dropdowns and ad new td

I have the following code:
<form action="" method="POST">
<?php
$count = isset($_POST['count']) ? $_POST['count'] : 1;
if($count > 11) $count = 11;
?>
<table>
<!-- Keeps track of the current number of rows -->
<input type="hidden" name="count" value="<?php echo $count+1; ?>"/>
<?php for($i = 0; $i < $count; $i++):
// Loop through all rows gathering the data here, and then creating the fields below
$val0 = isset($_POST['field'][$i]['0']) ? $_POST['field'][$i]['0'] : '';
$val1 = isset($_POST['field'][$i]['1']) ? $_POST['field'][$i]['1'] : '';
$val2 = isset($_POST['field'][$i]['2']) ? $_POST['field'][$i]['2'] : '';
?>
<tr>
<td><input name="field[<?php echo $i; ?>][0]" value="<?php echo $val0; ?>"/></td>
<td><input name="field[<?php echo $i; ?>][1]" value="<?php echo $val1; ?>"/></td>
<td><input name="field[<?php echo $i; ?>][2]" value="<?php echo $val2; ?>"/></td>
</tr>
<?php endfor; ?>
</table>
<input type="submit" value="click me" />
How can I make the fields into a dropdowns and when you press submit echo out the dropdown as text instead as a dropdown?
First: Fill in the following:
Make this to action="mytestpage.php"
Give this a name attribue like: name="send"
Give these fields types like: type="Text"
If you want a dropdown menu use <select> in combination with <option>...
Here is a start to learn how:
http://www.echoecho.com/htmlforms11.htm
To print your result do this:
if(isset($_POST['send'])
{
print($_POST['youroptionname']);
}
I hope it helped you.

Categories