Re: for each syntax [message #169613 is a reply to message #169611] |
Sun, 19 September 2010 00:35 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 9/18/2010 7:55 PM, GarryJones wrote:
> On Sep 19, 1:17 am, spamb...@milmac.com (Doug Miller) wrote:
>> Sometimes one needs to step back and think
>> "What am I really trying to accomplish here?". Without doing so, it's not
>> possible to consider alternative methods of solving the problem.
>
> I have a booking site where users can click on a trip.
>
> On the booking choice page there is a<tr><td> for each trip with a
> description pulled in from info on a mysql server dynamicaly
> To create the correct<tr><td>'s all I have to do is to add or remove
> an id number from the array. If the number is there it will create the
> <td> with the correct info.
>
> ie if the array is 111,112,113,114 then four<tr><td> are
> I place an ok box at the end of each<tr>
>
> To do this I make each<tr><td> its own unique form.
> Each ok box submits the form.
> To cut a corner I make each ok box redirect to the same page.
>
> The example code for 1 of these<tr> is
>
> <tr>
> <td width="650" valign="top" class="resmallefty">Chase The
> Sun<br>2010-10-02 -> 2010-10-12<br>9 400:-</td>
> <td width="150" valign="middle" class="barstyle">
> <FORM action="boksteg2.php" method="post" name="steg1109"
> id="steg1109"><input name="resmalval109" type="hidden" value="109">
> <input type="Submit" value = "Boka NU">
> </FORM>
> </td>
> </tr>
>
> Every<tr> has a form with a unique name.
>
> To create the above code I use this code for each value in the array
> (varid can be 109,110,111, etc as explained above
> ---------------------------------------------------------------------
> <?
> print '<tr><td>' . $var1 .'<br>';
> print $var2 . " -> " . $var3 ."<br>" . $var3 . ":-";
> echo '</td>';
> ?>
>
> <td>
> <FORM action="boksteg2.php" method="post" name="steg1<?= $varid ?>"
> id="steg1<?= $varid?>"><input name="resmalval<?= $varid?>"
> type="hidden" value="<?= $varid?>">
> <input type="Submit" value = "Boka NU">
> </FORM>
> </td>
> </tr>
> ----------------------------------------------------------------------
>
> As you can see the name of the form I am sending to is identical for
> all OK buttons
>
> On that page I need to set a value according to which ok button the
> user clicked on.
>
> if ($_POST['resmalval109'] == 109) {
> $resmalval=109;
> } elseif ($_POST['resmalval110'] == 110) {
> $resmalval=110;
> etc until all value found
>
> So if the user has clicked on the ok button for the form with the
> input name "resmalval109" the value I need to read in is 109
>
> if ($_POST['resmalval109'] == 109) {
>
> Gives yes, the input name resmalval109 is set to 109 because 109 is
> read in by the post. It then does not need to check for 110, 111 etc,
> it bypasses the rest of the if and I can now use my value to do what I
> need to do.
>
> When these id values change it would be nice if I don't have to edit
> the long-winded code, so I thought I could use "for each" and write
> the else /elseifs for each value in the array
>
> I may well be going about this the wrong way, but dont have more
> knowledge than that I pocess today.
>
>
> So any help appreciated
>
> Garry Jones
> Sweden
Why are you using different id's for values in every form? The browser
will only submit one form at a time.
I suggest you start with alt.html and get an understanding on how HTML
works. Your PHP will then be much easier.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|