PHP
Mark Musone
mmusone at shatterit.com
Fri Aug 22 17:35:01 EDT 2003
Ugh..ugly ulgy ugly..i think your confusing form entries with field
names:
This is your code:
<TR>
<TD>
<Input Type=\"checkbox\" Name=entry[0][] Value=1>
</TD>
<TD>
<input type=text size=15 maxlength=15 name=entry[1][]
Value=\"$row[1]\">
</TD>
<TD>
<input type=text size=15 maxlength=15 name=entry[2][]
Value=\"$row[2]\">
</TD>
<TD>
<input type=text size=8 maxlength=8 name=entry[3][]
Value=\"$row[3]\">
</TD>
<TD>
<Center>
<input type=text size=4 maxlength=4 name=entry[4][]
Value=\"$row[4]\">
</Center>
</TD>
<TD>
<Center>
<input type=text size=4 maxlength=4 name=entry[5][]
Value=\"$row[5]\">
</Center>
</TD>
<TD>
<input type=text size=25 maxlength=25 name=entry[6][]
Value=\"$row[6]\">
</TD>
</TR>
------------------------------------------------------------------------
-------
A couple of things: you're not incrementing the entry number, secondly,
you're overwriting entries with "rows" (I'm gonna call them fields)
A couple of options, separate the "rows" from "fields"
Also keep track of the row # I nthe code:
Change it to:
$x=0;
while ($row = mysql_fetch_row($result))
{
Print ("
<TR>
<TD>
<Input Type=\"checkbox\" Name=entry[$x] Value=1>
</TD>
<TD>
<input type=text size=15 maxlength=15 name=field[$x][1]
Value=\"$row[1]\">
</TD>
<TD>
<input type=text size=15 maxlength=15 name=field[$x][2]
Value=\"$row[2]\">
</TD>
<TD>
<input type=text size=8 maxlength=8 name=field[$x][3]
Value=\"$row[3]\">
</TD>
<TD>
<Center>
<input type=text size=4 maxlength=4 name=field[$x][4]
Value=\"$row[4]\">
</Center>
</TD>
<TD>
<Center>
<input type=text size=4 maxlength=4 name=field[$x][5]
Value=\"$row[5]\">
</Center>
</TD>
<TD>
<input type=text size=25 maxlength=25 name=field[$x][6]
Value=\"$row[6]\">
</TD>
</TR>
</TD>
</TR>
<TR><TD Colspan=7><img src=\"http://www.dd950.com/Home/dot.gif\" width=1
height=15></TD></TR>
");
$x++;
}
Now you'll end up with a simple 1 dimensional array called
$entry[somenumber]
That is either going to be set or unset..if that’s set, then for
whatever somenumber is, you simply access $field[somenumber][1-6]
------------------------------------------------------------------------
---------------------
Second option (theres a million ways to do the same thing in php)
And this might get closer to what you were trying to do, however it's a
bit more complicated:
$x=0;
while ($row = mysql_fetch_row($result))
{
Print ("
<TR>
<TD>
<Input Type=\"checkbox\" Name=entry[$x][0] Value=1>
</TD>
<TD>
<input type=text size=15 maxlength=15 name=entry[$x][1]
Value=\"$row[1]\">
</TD>
<TD>
<input type=text size=15 maxlength=15 name= entry[$x][2]
Value=\"$row[2]\">
</TD>
<TD>
<input type=text size=8 maxlength=8 name= entry[$x][3]
Value=\"$row[3]\">
</TD>
<TD>
<Center>
<input type=text size=4 maxlength=4 name= entry[$x][4]
Value=\"$row[4]\">
</Center>
</TD>
<TD>
<Center>
<input type=text size=4 maxlength=4 name= entry[$x][5]
Value=\"$row[5]\">
</Center>
</TD>
<TD>
<input type=text size=25 maxlength=25 name= entry[$x][6]
Value=\"$row[6]\">
</TD>
</TR>
</TD>
</TR>
<TR><TD Colspan=7><img src=\"http://www.dd950.com/Home/dot.gif\" width=1
height=15></TD></TR>
");
$x++;
}
Ths is really the same thing as above, and simply stuffs it all in a
single variable (entry) and just uses the first array element
entry[entrynumber][0] as a flag as to if that’s set.
To read the above, you first loop through the _first_ dimension and see
if it's set, then get those dimension numbers and loop through it for
the actual fields..for example (and I haven’t tested it, I'm just trying
off the cuff, so I may be off)
$entryarray=$_POST['entry'];
Foreach($entryarray as $entrynumber)
{
$validentries[]=$entrynumber;
}
foreach($validentries as $currententrynumber)
{
print $entryarray[$currententrynumber][1];
print $entryarray[$currententrynumber][2];
print $entryarray[$currententrynumber][3];
print $entryarray[$currententrynumber][4];
print $entryarray[$currententrynumber][5];
print $entryarray[$currententrynumber][6];
}
Hope this helps a little..
Again, I'd probably go with the first method..it's a bit eaiser to
manage..
Let me know if I simply confused you even more :^)
-Mark
-----Original Message-----
From: owner-nflug at nflug.org [mailto:owner-nflug at nflug.org] On Behalf Of
Robert Dege
Sent: Friday, August 22, 2003 2:04 PM
To: nflug at nflug.org
Subject: RE: PHP
Okay, Here are a few URLs:
#
# This one sorts each entry on a column basis
#
http://www.dd950.com/CURRENT/up2date-ONE.php // The Form selection
http://www.dd950.com/CURRENT/commit2db-ONE.php // The Form processor
http://www.dd950.com/CURRENT/up2date-ONE.phps // View SRC
http://www.dd950.com/CURRENT/commit2db-ONE.phps // View SRC
#
# This setup outputs each entry on a diagonal 2x array (I have no clue
why)
#
http://www.dd950.com/CURRENT/up2date-TWO.php // The Form selection
http://www.dd950.com/CURRENT/commit2db-TWO.php // The Form processor
http://www.dd950.com/CURRENT/up2date-TWO.phps // View SRC
http://www.dd950.com/CURRENT/commit2db-TWO.phps // View SRC
I had these in functions, but exanded them out since I'm trying to debug
the problem. ALso, the user/pass is no working yet, so just click
submit
button to view the results.
-Rob
>
> Yea, definitely post the URL..i'm not sure what you got going there..
>
> Maybe even a sample code snippet of how you are trying to access the
> arrays..
>
> Are you saying you each form is it's on dimension in the array? And
each
> element is the other one, for example:
>
> $form["form1"]["field1"]
> $form["form1"]["field2"]
> $form["form1"]["field3"]
>
> $form["form2"]["field1"]
> $form["form2"]["field2"]
>
> $form["form3"]["field1"]
> $form["form3"]["field1"]
>
> something like that??
>
> If that’s the case, and then I assume you're tying to access it like
> $_POST["form['form3']['field1']"] then you'll probably run into
> problems..
>
> PHP isn’t very good with directly mucking around with multiple
> dimensional arrays.
>
> The best way to access it is like this:
>
> $mypostforms=$_POST["forms"];
>
> then deal with $mypostforms directly ...
>
> print $mypostforms["form3]["field1"];
>
>
> or I could be way off as to what you are doing....i think more info is
> needed..
>
>
> -Mark
>
>
> -----Original Message-----
> From: owner-nflug at nflug.org [mailto:owner-nflug at nflug.org] On Behalf
Of
> Robert Dege
> Sent: Thursday, August 21, 2003 10:52 PM
> To: nflug at nflug.org
> Subject: PHP
>
>
> Okay, I know there's been a lot of buzz with php as of late, so maybe
> someone can help me out here.
>
> I'm trying to pass a 2-dimensional array between 2 webpages.
>
> The first page consists of a form with 6 fields. The webpage contains
> several instances of the same form so that the user can fill out
> multiple entries at once.
>
> When the 'Submit' button is clicked, the array is passed to the next
> webpage via $_POST. However, I'm having some trouble extrapolating
the
> data from the array. The data appears to be parsed by column instead
of
> by row.
>
> I can provide a URL if anyone is interested. I've set it up so that
the
> 2nd webpage outputs a 6x6 array so that it's easier to visualize the
> matrix.
>
> Dege
>
> So Many Things in Life Would Be Really Funny
> .... If They Weren't Happening To Me
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/2003
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/2003
>
>
>
>
Dege
So Many Things in Life Would Be Really Funny
.... If They Weren't Happening To Me
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/2003
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/2003
More information about the nflug
mailing list