Php

if your input is formed in a method=‘post’ form as:
<input type=‘text’ name=‘input[$r][$c]’>

then the value passed (once the form is submitted) should be referenced as
$_POST[‘input’][$r][$c]

as you can see im going to in put 2 on colms and 2 in rows

for ($c = 1; $c <= $columns * 4;$c++) {
echo “<input type=‘text’ name='input[”.$rows.“][”.$columns."]’ size=‘5’> ";
} echo "<br> ";

the colums is multiplied by four so in the 3rd and 4th textfield it is the Max
then the 5th and 6th textfield is the Need so im going to make it like this

$_POST[‘input’][1][5] = $_POST[‘input’][1][1] - $_POST[‘input’][1][3];

is it correct ??

I would not do that. Seperate them into different arrays (you’re trying to put them all into the ‘input’ array).

how? i cant figure out the answer T_T

Real quick like:


<?php

$columns = $_POST['columns'];
[COLOR="#008000"]for($i=1; $i<= $columns; $i++)
{

echo "Instance $i = "."<input type='text' size='2' name='r[]'>"." ";

}[/COLOR]
echo"<br>Alocation Max Need Work";
if (isset($_POST['submit'])) {

// set variables from form input
$rows = $_POST['rows'];
$columns = $_POST['columns'];
// loop to create rows
[COLOR="#FF0000"]for ($r = 1; $r <= $rows; $r++) {
echo "<br>";
// loop to create columns
for ($c = 1; $c <= $columns;$c++) {
echo "<input type='text' name='input[".$r."][".$c."]' size='5'> ";
} echo "<br> ";
}[/COLOR]
echo " ";
}
?>

The green section creates your ResourceMax section.
The red section creates -1- of your inputs (lets say Allocation, because that came first in the list). Copy and paste the red code again below it, change ‘input’ to something else, say ‘max’. Now you’ve got spaces for your Allocated, and your Max. Need and Available dont need to be filled in by the user because they are calculated, so dont display anything for those.

<?php

$columns = $_POST[‘columns’];
for($i=1; $i<= $columns; $i++)
{

echo “Instance $i = “.”<input type=‘text’ size=‘2’ name=‘r’>”." ";

}
echo"<br>Alocation Max Need Work";
if (isset($_POST[‘submit’])) {

// set variables from form input
$rows = $_POST[‘rows’];
$columns = $_POST[‘columns’];
// loop to create rows
for ($r = 1; $r <= $rows; $r++) {
echo “<br>”;
// loop to create columns
for ($c = 1; $c <= $columns;$c++) {
echo “<input type=‘text’ name='input[”.$r.“][”.$c."]’ size=‘5’> ";
} echo "<br> ";
}
echo " ";
}

for ($r = 1; $r <= $rows; $r++) {
echo “<br>”;
// loop to create columns
for ($c = 1; $c <= $columns;$c++) {
echo “<input type=‘text’ name='max[”.$r.“][”.$c."]’ size=‘5’> ";
} echo "<br> ";
}
?>

its running but the the Max is below the Allocated can we put it in the left side of the Allocated?

wrap it in table tags, 1 row 2 columns put the max entry in column 1, then the Allocated entry.

i got a problem about the the Table tagging when I tag the Max it goes in below the allocated can you find out the problem

<?php
echo"<table border = 5%>";
$columns = $_POST[‘columns’];
for($i=1; $i<= $columns; $i++)
{

echo “Instance $i = “.”<input type=‘text’ size=‘2’ name=‘r’>”." ";

}
echo"<br>Alocation Max Need Work";
if (isset($_POST[‘submit’])) {

// set variables from form input
$rows = $_POST[‘rows’];
$columns = $_POST[‘columns’];
// loop to create rows
for ($r = 1; $r <= $rows; $r++) {

// loop to create columns
for ($c = 1; $c <= $columns;$c++) {
echo “<td><input type=‘text’ name='input[”.$r.“][”.$c.“]’ size=‘5’> </td>”;
} echo “<tr>”;
}

}

for ($r = 1; $r <= $rows; $r++) {

// loop to create columns
for ($c = 1; $c <= $columns;$c++) {
echo “<td><input type=‘text’ name='max[”.$r.“][”.$c.“]’ size=‘5’></td> “;
} echo " <tr>”;
}
echo”</table>";
?>

I’m going to ask a question, and I’m trying not to be offensive here.

Do you know HTML?

Yeah I know a little

Why are you doing this assignment in the form of a webpage, if you only know html a little?

I know HTML but not all…
in our assignment it is just given to us and i dont know why she gives me this hard assignment
i was just asking some of your help if you please i really got hard on the logic in this assignment but im trying my best to undserstand it…T_T

If you want the Max boxes to appear before the Allocated boxes… the code for Max will have to be before the code for Allocated.

i got it now dude…
about the needs function how can i obtain it??

<?php
echo"<table border = 5%>";
$columns = $_POST[‘columns’];
for($i=1; $i<= $columns; $i++)
{

echo “Instance R$i : “.”<input type=‘text’ size=‘2’ name=‘r’>”." ";

}

if (isset($_POST[‘submit’])) {

// set variables from form input
$rows = $_POST[‘rows’];
$columns = $_POST[‘columns’];

		echo"&lt;br&gt;&lt;br&gt;ALLOCATION&lt;br&gt;&lt;br&gt;";

		for($i=1; $i&lt;= $columns; $i++)  //loop for the Resource R1++
		{
		echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R ".$i."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		}


	for ($r = 1; $r &lt;= $rows; $r++) {		// loop to create rows
			echo" &lt;br&gt;P ".$r;

		for ($c = 1; $c &lt;= $columns;$c++) {// loop to create columns in Allocated

				echo "&lt;input type='text' name='input[".$r."][".$c."]' size='5' &gt; ";
					} echo "&lt;br&gt;";
						}

					}
					
		echo"&lt;br&gt;MAX&lt;br&gt;";
			for ($r = 1; $r &lt;= $rows; $r++) {
				echo" &lt;br&gt;P ".$r;
					for ($c = 1; $c &lt;= $columns;$c++) {// loop to create columns in Max
		
			echo "&lt;input type='text' name='max[".$r."][".$c."]' size='5'&gt; ";
				} echo "&lt;br&gt;";
					}
						
						?&gt;

thanks for the help
this is my current PHP code now its kinda good now…
can you help me how to do the Need And Work…

i have a problem in PHP banker’s to , and my problem is , is about getting the value from the table that you created ,
for ($r = 1; $r <= $rows; $r++) {
echo “<br>”;
// loop to create columns
for ($c = 1; $c <= $columns;$c++) {
echo “<input type=‘text’ name='input[”.$r.“][”.$c."]’ size=‘5’> ";
} echo "<br> ";
}

How can i get the value from the " input[“.$r.”][“.$c.”] " i’m confuse , how can you say that is an array ,
when you do not declare array at the top
for example:

$allocation = array(‘r’=> array(),
‘c’=> array());

that actually a two dimentional array, my real question is, how can you implement the two dimenstional array ? and
how can i get the value that they inputed from the table matrix that i show above from you example ??

Sir StarLion , please give us the php code how can we display the obtain input from Allocation and Need , i am having a hard time
in getting there input in the table that they inputed from

sir StarLion , please help me .

Sir StarLion , how can we get the input value of the user from the table , i am really having a hard time , in getting the value of the table which the user inputed .
Sir, StarLion , can you give us a code which get’s the value of the table which the user inputed then display it !! please help me.

This is also a Banker’s algorithm problem
Sir StarLion , how can we get the input value of the user from the table , i am really having a hard time , in getting the value of the table which the user inputed in the table
for ($r = 1; $r <= $rows; $r++) {
echo “<br>”;
// loop to create columns
for ($c = 1; $c <= $columns;$c++) {
echo “<input type=‘text’ name='input[”.$r.“][”.$c."]’ size=‘5’> ";
} echo "<br> ";
}
Sir, StarLion , can you give us a code which get’s the value of the table which the user inputed and display it !!
or either display the Need which result from “MAX - Allocation”. please help me , its badly needed !!

First of all, ‘how i can say it is an array’, is that at this point of echoing it out, it’s an HTML Input array, not a PHP array.

When you get to the parsing stage (after the user pushes the “Submit” button), this array would be referenced in a double-nested loop of values $r and $c by: $_POST[‘input’][$r][$c]