Jump to content

[SOLVED] while loop


almightyegg

Recommended Posts

I want to loop 25 times and inside the loop it is inserting a new row of data, which changes depending how many loops it has done so far...

maybe this explains it better:

// on the first time it loops
while($some_variable *25 (shrugs)){
$loop = mysql_query("INSERT INTO ranks SET `rank` = '1'");
}
// on the second time it loops
while($some_variable *25 (shrugs)){
$loop = mysql_query("INSERT INTO ranks SET `rank` = '2'");
}
// and the third...
while($some_variable *25 (shrugs)){
$loop = mysql_query("INSERT INTO ranks SET `rank` = '3'");
}

I think I have to do something with $i ???

 

???

Link to comment
https://forums.phpfreaks.com/topic/62561-solved-while-loop/
Share on other sites

Hmmm...I think I did something wrong...

 

This is my whole script

$sel = mysql_query("SELECT * FROM clutch");
while($clutch = mysql_fetch_array($sel)){

for ($i = 1; $i <= 3; $i++) {
$j = 1;
while ($j <= 25) {
	mysql_query("INSERT INTO ranks (`rank`, `society`) VALUES('" . $i . "', '{$clutch['id']}')") or die(mysql_error());
	$j++;
}
}

}

It shoudl have written 25 rows per row in a different table:

Rank|Society

1    | 10

2    | 10

etc..

25  | 10

1    | 11

2    | 11

 

Instead it has written:

              Rank | Society

25 rows of|1    | 10

25 rows of|2    | 10

etc...

25 rows of|1    | 11

25 rows of|2    | 12

 

why??

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/62561-solved-while-loop/#findComment-311411
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.