|
Posted by Steve on 04/01/07 04:18
"Erik Kullberg" <erik.kullberg@telia.com> wrote in message
news:YhCPh.37622$E02.15287@newsb.telia.net...
|I have a form with a 6*16 input table (double indexed array). The values
are
| preset, but can be changed by the user. If I have understood it correctly,
| GET cannot handle arrays, only scalar values. But if I can generate new
| variable names in run time, I could use something like $arr5x13 instead of
| $arr[5][13].
| Is that possible? How?
first, you do NOT understand it correctly.
<input name="arrayVariable[]" type="text" value="hello world">
will post as an array.
<a href="?arrayVariable[]=hello+world">
will get as an array.
i think you're taking the long, unimaginative approach by creating a two
dimensional array to do this. with a little math, you can use a single
number to determine what row/column/cell was entered/edited...as long as you
know how many columns there were. try it.
let's say these are the values in the table being submitted:
A B C D
E F G H
I J
4 columns. our html array from right to left, top to bottom would be turned
into a serial concern - a is 0, b is 1, e is 4, h is 7...and so on. so what
row is the value of F found in? well, the array index would be 5. let's do
the math...
floor(5 / 4) = 1 (zero-based rows)
so, what column is F in? let's do the math...
5 % 4 = 1 (also zero-based columns)
so, that makes it extremely easy and compact to both push to html, but to
process when it comes back to the server. your form would simply be using
name="index[]" for all the cells of your input table/form.
btw, F here is located at, of course, 1, 1. if you don't like how this is
zero-based, just add 1 to the product of both calculations. here's a proof
of concept...it will print out what you are trying to simulate with a
multi-dimensional array (array[0][3] ... as in row 0, column 3):
<?
$columnCount = isset($_REQUEST['columnCount']) ? $_REQUEST['columnCount'] :
7;
?>
<style type="text/css">
table
{
border-collapse : collapse;
border-padding : 2px;
border-width : 0px;
border-spacing : 0px;
}
td
{
font-family : arial;
font-size : 7.25pt;
}
</style>
<form method='get'>
<table>
<tr>
<td colspan="<?= ($columnCount - 1) ?>">
change number of columns to display to:
<input name="columnCount" type="text" value="<?= $columnCount ?>"
autocomplete="off">
<input type="submit" value="Change ...">
</td>
</tr>
<?
for ($i = 0; $i < 26; $i++)
{
$chr = chr(65 + $i);
$column = $i % $columnCount;
$row = floor($i / $columnCount);
if ($column == 0 && $i){ echo '</tr><tr>'; }
echo '<td>' . $chr . '<sup>(' . $row . ', ' . $column . ')</td>';
}
?>
</table>
</form>
have fun...hope the suggestion helps.
Navigation:
[Reply to this message]
|