Page 1 of 1

foreach problem.

Posted: Sun Oct 23, 2005 1:39 pm
by einamiga
the foreach in my code give me a syntax error....can't find what is wrong...her is the code...hope that some one can help me :)

Code: Select all

<?php
echo "<h2>Takk for din bestilling {$_GET['navn']}</h2>";

echo "Størrelse: <b>" . $_GET['str'] . "</b><br>";

if ( isset($_GET['fyll']) ) {

  echo "Valgt fyll:<ul>";

  foreach ($_GET['fyll'] as $fyllnavn => $avkrysset) {

    echo "<li>$avkrysset (nøkkel er $fyllnavn)</li>";

  }

  echo "</ul>";

}
?>
Burrito: Please use

Code: Select all

tags when [url=http://forums.devnetwork.net/viewtopic.php?t=21171]posting code in the forum[/url].[/size]

Posted: Sun Oct 23, 2005 3:51 pm
by Burrito
at first glance the syntax looks fine to me...are you sure that $_GET['fyll'] is an array?

Posted: Sun Oct 23, 2005 4:39 pm
by Jenk
I didn't think it was possible to have arrays passed via $_GET, though I could be wrong.

Posted: Sun Oct 23, 2005 4:39 pm
by feyd
it's quite possible ;)

Posted: Sun Oct 23, 2005 5:38 pm
by jayshields
instead of echoing "safjbjb" . "dknln" use "dfknsdfhn", "dsnlsdn" or just start a new echo line for each part.

just an idea :)

Posted: Sun Oct 23, 2005 6:37 pm
by einamiga
Jay it did not work......

It's the foreach that gives me problem...
the error reads..

Warning: Invalid argument supplied for foreach() in D:\sokkit\site\vis_pizza.php on line 8

It shoud work :cry:

Posted: Sun Oct 23, 2005 7:16 pm
by feyd
if it isn't an array or object, it will not work. var_dump() the variable to see what it is..

Re: foreach problem.

Posted: Sun Oct 23, 2005 9:23 pm
by harrisonad

Code: Select all

echo "Valgt fyll:<ul>";

  if (is_array($_GET['fyll'])) {

      foreach ($_GET['fyll'] as $fyllnavn => $avkrysset) {

        echo "<li>$avkrysset (nøkkel er $fyllnavn)</li>";

      }

  }

  echo "</ul>";

Posted: Sun Oct 23, 2005 10:32 pm
by einamiga
The problem is solved...thanx feyd :P
Think I am blind...name="fyll" sometings missing? Yes [] :oops:

Posted: Sun Oct 23, 2005 10:44 pm
by Jenk
feyd wrote:it's quite possible ;)
I knew it was possible via $_POST, just didn't think $_GET could, or atleast, it is limited with how many characters can be sent via the URI :)