Input Fibonacci in table generate PHP - 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>

Related

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

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

Do while loop not looping in php

I've been working a loop that repeats incrementally, while displaying the kelvin and fahrenheit counterparts in a table. I'm using a do while loop to do so, however the function does not loop, and does not start on the correct number from the form.
The code I've done so far is:
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<?php
$a = 1;
if ($_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
} while ($x >= $end);
}
?>
<?php
if ($a != 1) {
?>
<table>
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<tr>
<th>
<?php
echo "$x degrees <br />";
?>
</th>
<th>
<?php
echo "$y degrees <br />";
?>
</th>
<th>
<?php
echo "$z degrees <br />";
?>
</th>
</tr>
</table>
<?php
}
?>
</body>
Would I have to include while loops in the echo part of the table for it to loop? And how would I be able to have the loop start on the same number as the form?
is it you need?
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<table >
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<?php
$a = 1;
if (isset($_POST['sub']) && $_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
?>
<?php
if ($a != 1) {
?>
<tr>
<th><?php echo "$x degrees <br />"; ?></th>
<th><?php echo "$y degrees <br />"; ?></th>
<th><?php echo "$z degrees <br />";?></th>
</tr>
<?php
}
} while ($x >= $end);
}
?>
</table>
</body>

arrange checkbox values in two columns

I have a form with check box values i want to arrange the checkbox in two columns instead of
one single long column.
How can i split it to two columns ?
Here is the code :
<form id="form" name="form" method="post" action="">
<table width="502" border="0">
<tr>
<td>
Name :
<input type="textbox" name="rcv_group_name" value="">
<input type="hidden" name="add" value="add" />
</td>
</tr>
<tr>
<td align="left">
<strong>HEADING</strong>
<?php
$q = "select * from Config_RCV";
$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) > 0)
{
$k=0;
while ($row = mysqli_fetch_array($r,MYSQLI_NUM))
{
?>
<br> <input type="checkbox" name ="rcv_val[]" value ="<? echo $row[0];?>" /> <? echo $row[1];?>
<?
$k++;
}
}
?>
</td>
</tr>
<tr>
<td align="right"><input type="submit" name="Submit" id="Submit" value="Submit" style="background-color:#999" />
< /td>
<td height="26" align="left"> </td>
<td> </td>
</tr>
</table>
<form>
add another table and make 2 columns by splitting 2'nd result:
if (mysqli_num_rows($r) > 0) {
$k=0;
echo '<table><tr>';
while ($row = mysqli_fetch_array($r,MYSQLI_NUM)) {
?>
<td><input type="checkbox" name ="rcv_val[]" value ="<?php echo $row[0];?>" /> <?php echo $row[1];?> </td>
<?php
$k++;
if($k%2 == 0){
echo '</tr><tr>';
}
}
echo '</table>';
}
use your $k
if ($k%2==0){
echo "<br />";
}
instead of the lone now
Using tables like above will probably be better for looks
You could just add a second column to your table:
echo "<tr>";
$i = 0;
while ($row = mysqli_fetch_array($r,MYSQLI_NUM)) {
if ($i++%2==0) {
echo "</tr><tr>";
}
echo "<td>".$CELL_CONTENT_HERE."</td>";
}
echo "</tr>";

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.

Php: on submit echo td fields 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'][$count]['0']) ? $_POST['field'][$count]['0'] : '';
$val1 = isset($_POST['field'][$count]['1']) ? $_POST['field'][$count]['1'] : '';
$val2 = isset($_POST['field'][$count]['2']) ? $_POST['field'][$count]['2'] : '';
?>
<tr>
<td><input name="field[<?php echo $count; ?>][0]" value="<?php $val0; ?>"/></td>
<td><input name="field[<?php echo $count; ?>][1]" value="<?php $val1; ?>"/></td>
<td><input name="field[<?php echo $count; ?>][2]" value="<?php $val2; ?>"/></td>
</tr>
<?php endfor; ?>
</table>
<input type="submit" value="click me" />
</form>
The problem is when I press submit it add 3 other fields but it clears the other fields. How can I keep the content from the fields but make them uneditable?
You are not echoing your values and your $count should be $i, as you'll end up with same field names
<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" />
for($j=0;$j<3;$j++){
echo '<input type="hidden" name="field['.$i.'][0]" value="'.$_POST[field][$i][0].'" />';
}

Categories