'for'-loop problem

Codes here !

Moderators: egami, macek, gesf

Post Reply
User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Fri Dec 27, 2002 8:27 pm

Hi, beloven,
I don't understand your case too much...
What are you trying to do exactly??

If you do something like this -->

Code: Select all

$submit="ok";
$aantal=5;

if ($submit) {
   for($i = 1; $i <= $aantal; $i++){
      echo $Nummervar = "Nummer" .$i."<br>";
      echo $Artiestvar = "Artiest" .$i."<p>";
   }
}

You will see that it works just fine.
You get this -->
Nummer1
Artiest1
Nummer2
Artiest2

Nummer3
Artiest3

Nummer4
Artiest4

Nummer5
Artiest5


So, there's no problem with numbers.
The weird thing comes with the Mysql query.
I don't think you want to do what the script does.
If you have a look at the script you'll see that what you are doing is update the same row time after time.

Maybe you want something like this -->

Code: Select all

if ($submit) { 
   for($i = 1; $i <= $aantal; $i++){
      $Nummervar[$i] = "Nummer" .$i;
      $Artiestvar[$i] = "Artiest" .$i;
      if ($id) {
         $sql = "UPDATE cd SET Nummer='$Nummervar[$i]',Artiest='$Artiestvar[$i]',Cd='$Cd' WHERE id='$id'";
      } else {
         $sql = "INSERT INTO cd (Nummer,Artiest,Cd) VALUES ('$Nummervar[$i]','$Artiestvar[$i]','$Cd')";
      }
   }
}

Well,
I don't have enough data to guess what those vars do, or where they come from.

I hope it helped
;)

Post Reply