'for'-loop problem

A

Anonymous

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

If you do something like this -->
Code:
$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:
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
;)
 
Back
Top