Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lost and not sure where to go

Status
Not open for further replies.

tyrannus

MIS
Apr 6, 2006
115
US
I have a form that has multiple input fields named script1, script2, script3..... i think you get it...

I am passing these to a php function. I am wanting to loop through these and input their values into a single field in a table. so basically it will loop through and put the value of script1 into field script, then put the value of script2 into the field called script...

I am lost and don't know where to go.
 

Name all your fields script[] , then, simply do a
$your_db_data = implode("", $_POST["script"])
and store $your_db_data in the "field" column ... if that's what you really want to do.
 
While Sleidia's suggestion is the recommended method, if for any reason you cannot change the name of your fields.
You can do something like this to cycle through them:

Code:
$fieldcount="5";  [green]\\Define the number of fields you have for the loop[/green]
$script=""; [green]\\Define a receiving Variable for the contents of the looped fields[/green]
for($i=1;$i<=$fieldcount;$i++){ [green]\\Start Loop[/green]
$value="script" .$i; [green]\\Generate form field names.[/green]
$script.=$_POST[$value] . ","; [green]\\Use form field name to get contents and place into a comma separated string.[/green]
}

You can then use the $script variable in your insert statement.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Could I use the same concept to build a multidimensional array?
 
Using Sleidia's method, your script values are already in an array. So you could have a new array and stick those values in there, in a new key.

Using mine you could loop through them and build the array just as you would the string. Although I'm not sure what purpose having a multidimensional array would serve.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I actually ended up going in a totally different direction, but thanks, I was able to use your suggestions to make it do what I wanted it to do.
 
Glad we could help.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top