I am working on what I think is a great program and I am needing some coding help. It is probably simple to you but I cannot get it to work. I have 10 input lines that have an input for a link and an input for a file name. echo "<form action=\"$PHP_SELF?xfer=true\" method=post> from(http://): <input name='from'> to(filename): <input name='to'><br><br> from(http://): <input name='from2'> to(filename): <input name='to2'><br><br> from(http://): <input name='from3'> to(filename): <input name='to3'><br><br> from(http://): <input name='from4'> to(filename): <input name='to4'><br><br> from(http://): <input name='from5'> to(filename): <input name='to5'><br><br> from(http://): <input name='from6'> to(filename): <input name='to6'><br><br> from(http://): <input name='from7'> to(filename): <input name='to7'><br><br> from(http://): <input name='from8'> to(filename): <input name='to8'><br><br> from(http://): <input name='from9'> to(filename): <input name='to9'><br><br> from(http://): <input name='from10'> to(filename): <input name='to10'><br><br> <input type=submit value=\"transfer\"> </form>"; Code (markup): I have set up 2 arrays - one for to and one for from. $from=$_POST[from];$from2=$_POST[from2];$from3=$_POST[from3];$from4=$_POST[from4];$from5=$_POST[from5];$from6=$_POST[from6];$from7=$_POST[from7];$from8=$_POST[from8];$from9=$_POST[from9];$from10=$_POST[from10]; $to=$_POST[to];$to2=$_POST[to2];$to3=$_POST[to3];$to4=$_POST[t04];$to5=$_POST[to5];$to6=$_POST[to6];$to7=$_POST[to7];$to8=$_POST[to8];$to9=$_POST[to9];$to10=$_POST[to10]; $from = array($from,$from2,$from3,$from4,$from5,$from6,$from7,$from8,$from9,$from10); $to = array($to,$to2,$to3,$to4,$to5,$to6,$to7,$to8,$to9,$to10); $i = $from; $j = $to; Code (markup): I am then trying to use this code to step through these variables 10 times. for ($i=0,$j=0;$i<sizeof($from),$j<sizeof($to);$i++,$j++) Code (markup): I then have a function that is called by the code above and it is run ten times. I would put it on here but it is what makes the whole thing work and I want to keep it secret for now. I do not get any errors while running the script but instead of it going through the variables it just repeats the first one 10 times. Can anyone see where I am going wrong? Am I going about this the wrong way?
why: for ($i=0,$j=0;$i<sizeof($from),$j<sizeof($to);$i++,$j++) PHP: The size of $from and $to should be equal, isn't it? Why not use simple foreach($from as $key=>$value) PHP: Seeing how you are created two non-associative arrays with related elements, key from one can be used to fetch corresponding element from other..
From what I read I thought sizeof counted the number variables. There are 10 variables for each. The reason I am tracking both is so that if any variable is empty the for loop will stop. I know I need to write some code to check for empty fields but right now I am just wanting to get this working.
I do not see how this is going to help. foreach uses related variables. I am dealing with two unrelated. One is a link and one os a filename. I could nest the loops but that is more code.
Well, I dont see anything that could prevent your code to pick up past first variable.. Must be something wrong in your function.. Is it intentional though? $from=$_POST[from];$from2=$_POST[from2];$from3=$_POST[from3];$from4=$_POST[from4];$from5=$_POST[from5];$from6=$_POST[from6];$from7=$_POST[from7];$from8=$_POST[from8];$from9=$_POST[from9];$from10=$_POST[from10]; $to=$_POST[to];$to2=$_POST[to2];$to3=$_POST[to3];$to4=$_POST[t04];$to5=$_POST[to5];$to6=$_POST[to6];$to7=$_POST[to7];$to8=$_POST[to8];$to9=$_POST[to9];$to10=$_POST[to10]; $from = array($from,$from2,$from3,$from4,$from5,$from6,$from7,$from8,$from9,$from10); $to = array($to,$to2,$to3,$to4,$to5,$to6,$to7,$to8,$to9,$to10); $i = $from; $j = $to; and then for ($i=0,$j=0;$i<sizeof($from),$j<sizeof($to);$i++,$j++)
The way I start into the funtion is I am not sure what you mean by intentional. It is not intentional by me. I can pm the code for the funtion if you will keep it private. I am planning on putting this out for sale. If you want to help me build this program maybe we can work something out.
Look at the part in red in your code, You assign $i and $j with $from and $to, then reassign the same variables as 0. was it intentional?
Right now I am just pretty dumb. It has been a while since I have tried doing any real coding and I am overlooking a bunch of stuff.