Re: Foreach ...... Help
| From: | Remon Redika | Date: | Thu, 07 Nov 2002 05:58:24 +0000 |
| Subject: | Re: Foreach ...... Help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-123107@lists.php.net to get a copy of this message | ||
Sorry before.
I Just to try to Explain my Problem
may be this my reason ..
I have Two Text Fields
The First Text Field i call it "InputX" <input type='text' name='InputX' size='50'>
and The Second Text Field I Call it "InputY", Generatable Field (using javascripts), if User Click the Button ("AddRow's Button") for Generated / produce the InputY, may be like the sample..
Blabla.innerHTML = "<input type='text' name='InputY' size='50'>" ;
I need to insert data from Fields to the server, the Code will Post the value of Fields ("InputX" and "InputY(s)") by once submit to the server, and amount of value of data saved depent on how many "InputY" I have, or how many times User click my "AddRow" Button and fill Text Fields.
This The sample result data will send to server in once post data, if user click 5 Times "AddRow's Button". and fill it's with these value
INPUTXVALUE INPUTYVALUE INDEX SUB1 INDEX SUB2 INDEX SUB3 INDEX SUB4 INDEX SUBXi have done before with my asp code. and it's Worked. <% i = 0 Inputx = request("Inputx") dim vary(100) for each y in request("InputY")
vary(i) = y
i = i + 1
next
for each x in request("inputY")
insertq = "Insert into Nsoftware(X, Y) values ('" & Inputx & "','" & vary(i) & "')"
set save = conn.execute(insertq)
i = i + 1
next
%>
I just to translate from asp code to php code
I try this code with php, but i still found an Error.
<?php
//$vary(100);
$i = 0;
foreach($InputY as $y){
$vary[$i] = $y;
$i++;
}
foreach($InputX as $x){
$insertq = "Insert into NSoftware (X, Y) values ('$InputX','$vary[$i]')";
echo $insertq."<br>";
mysql_query($insertq);
$i++;
}
?> <--- 55
Parse error: parse error, unexpected $ in /home/intra/Inventroot/software/savedata.php on line 55
i got error out of range of my code..,
or may be these not a good idea to translate my asp code to php??
sorry about my english
Rasmus Lerdorf writes:
Your code is bogus. You probably want: $vary[$i] = $y; And $vary(100) also makes no sense. Also, why are you looping through the $InputY array and putting all the values into $vary? Why not just do $vary = $InputY; ? If it is because you need to renumber the indices, have a look at the array_values() function. -Rasmus On Thu, 7 Nov 2002, Remon Redika wrote:Parse error: parse error, unexpected '=' in /home/intra/Inventroot/software/savedata.php on line 35 <?php $vary(100); $i = 0; foreach($InputY as $y){Hi Remon,$vary($i) = $y; <---------line 35 $i++; }foreach($Nama_Software as $x){$insertq = "Insert into NSoftware (X, Y) values('$InputX','$vary($i)')";echo $insertq."<br>"; mysql_query($insertq); $i++; }?> Thank's Jon Haworth writes:It would be helpful if you could show us this error message.I try this script with php, but i found an Error.At the very least, you should change this line to $vary = array(); Cheers Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php$vary(100);-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php