Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
multi dimensional array help
Old 09-16-2009, 02:42 PM multi dimensional array help
Dale Hodge's Avatar
Skilled Talker

Posts: 63
Location: Syracuse, ny
Trades: 1
Ok here is what I am trying to do:

Code:
<?
$gen=$_POST['gen'];
if ($gen) {
?>
<form method="post" action="genfields.php">
Table Name <input type="text" name="table" value="<? echo $table ?>"><BR><BR>
<?
// take input from some fields from a form

$fld=$_POST['field'];
$typ=$_POST['type'];
$siz=$_POST['size'];

$x = 1;

// When I try to get all of the fields into multiple key,value pairs like this
// it doesn't work. If I do one while statement like this at a time it
// works but not with more than one.

while (list($key0,$val0) = each($fld))
{
while (list($key1,$val1) = each($typ))
{
while (list($key2,$val2) = each($siz))

$lval = strtolower("$val0");
$newval = str_replace(" ","_","$lval");
?>
Field <? echo $x ?>: <input type="<? echo $val1 ?>" name="field[<? echo $x ?>]" size="<? echo $val2 ?>" value="<? echo $val ?>"><BR><BR>
<?
}}
++$x;} // end while

$x1 = $num +1;
?>
Field <? echo $x1 ?>: <input type="text" name="field[<? echo $x1 ?>]" size="25" value=""><BR><BR>
<input type="hidden" name="famounts" value="<? echo $x1 ?>">
<input type="hidden" name="gen" value="gen">
<input type="submit" name="add" value="Add Another"><BR><BR>
<input type="submit" value="Go!">
<?
exit;}
?>
Any help would be great.
Dale Hodge is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-16-2009, 09:36 PM Re: multi dimensional array help
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
is it just me or does this script not make any sense?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 09-16-2009, 10:30 PM Re: multi dimensional array help
Dale Hodge's Avatar
Skilled Talker

Posts: 63
Location: Syracuse, ny
Trades: 1
The script makes sense to me. all I want to know is how to take multiple input fields from a form then put them into seperate arrays using while loops.

Thanks
Dale Hodge is offline
Reply With Quote
View Public Profile
 
Old 09-17-2009, 12:33 AM Re: multi dimensional array help
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
What does the original form (the form that directs to this script) look like?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 09-17-2009, 12:54 AM Re: multi dimensional array help
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Values from a submited form is automatically treated as an array if you add "[]" to the fields' name. As in

PHP Code:
<form ...>
Field 1 <input type="text" name="my_field[]">
Field 2 <input type="text" name="my_field[]">
Field 3 <input type="text" name="my_field[]">
Field 4 <input type="text" name="my_field[]">

<
input type="submit">
</
form
On the page that receive the form:
PHP Code:
<?php

$fields 
$_POST['my_field'];
echo 
"<pre>";
print_r($fields);
echo 
"</pre>";

/*
This will output the $field variable, just to show you that it is an array.
It will look something like

Array
(
   [0]   =>   "first value...",
   [1]   =>   "seccond value...",
   [2]   =>   "third value...",
   [3]   =>   "fourth value..."
)

*/

?>
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to multi dimensional array help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33238 seconds with 12 queries