Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.