You are here: Re: Define new variables during runtime? « All PHP « IT news, forums, messages
Re: Define new variables during runtime?

Posted by Erik Kullberg on 04/01/07 08:40

Thanks, Steve,
You hae been most helpful!
I can pass a one-dim array, but not a two-or-more-dim array - correct?

It΄s about a linear aerodynamic 6 degrees of freedom model. The coefficients
(the table elements) are traditionally handled in named chunks of 3, 9 or
the whole batch as one. But the elements also have their own individual
names, which leads to my next question:
Is it possible to superimpose variable names, so I can point at a certain
value with the name that is appropriate according to the context?
I cannot find anything about this in the PHP documentation ...

/ Erik



"Steve" <no.one@example.com> skrev i meddelandet
news:6qGPh.9003$fQ1.6121@newsfe12.lga...
>
> "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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация