foreach problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
einamiga
Forum Newbie
Posts: 3
Joined: Sun Oct 23, 2005 1:32 pm

foreach problem.

Post 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]
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

at first glance the syntax looks fine to me...are you sure that $_GET['fyll'] is an array?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

I didn't think it was possible to have arrays passed via $_GET, though I could be wrong.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's quite possible ;)
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

instead of echoing "safjbjb" . "dknln" use "dfknsdfhn", "dsnlsdn" or just start a new echo line for each part.

just an idea :)
einamiga
Forum Newbie
Posts: 3
Joined: Sun Oct 23, 2005 1:32 pm

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if it isn't an array or object, it will not work. var_dump() the variable to see what it is..
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Re: foreach problem.

Post 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>";
einamiga
Forum Newbie
Posts: 3
Joined: Sun Oct 23, 2005 1:32 pm

Post by einamiga »

The problem is solved...thanx feyd :P
Think I am blind...name="fyll" sometings missing? Yes [] :oops:
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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 :)
Post Reply