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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

posted variables indefinite number

Status
Not open for further replies.

derketa

Programmer
May 13, 2002
43
0
0
TR
Hi,

I am posting variables to a new page,i have n variables
like $_POST[s1],$_POST[s2],....

i want to update my database but i could not write the variable names in a for loop

for ($i=1;$i<=;$count){
$startDate=$_POST["s".$i];
}


but did not work:)
in fact i dont know how to write variable name as a variable, can anyone help me?
 
Where do the varibles come from?
Could you handle them in an array or is it necessary to keep a correlation between the variable name and the content?
Simply naming the <input name="myArray[]" etc. would achieve that.
 
umm - I hope I understand the problem correctly, but this looks to me like the perfect opportunity to use an enumerator ... i.e :

foreach ($_POST as $paramname=>$value) {
//// Paramname is here only to be a syntax place holder, you can also use ($_POST as $value) and it will work fine.
$startdate = $value;
}

foreach will use the interval hash pointer to run through the whole array and pull out all values that exist there.
Paramname can be used to verify the current cell's name, so you grab only the ones named s# ... you can verify this with a preg_match('/s\w+/i',$paramname);

you can combine foreach with the input field method suggested above by DRJ478, and then use

foreach ($_POST['myArray'] as $value) {
if ($value) {
$startdate = $value;
}
}

i.e, just check if value has any kind of value inside and if it does, roll the logical ball ...
 
Thank you very much, it is working now:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top