almightyegg Posted July 30, 2007 Share Posted July 30, 2007 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 More sharing options...
hitman6003 Posted July 30, 2007 Share Posted July 30, 2007 for ($i = 1; $i <= 3; $i++) { $j = 1; while ($j <= 25) { mysql_query("INSERT INTO ranks SET `rank` = '" . $i . "'"); $j++; } } Or change the while loop to another for loop...works either way Link to comment https://forums.phpfreaks.com/topic/62561-solved-while-loop/#findComment-311390 Share on other sites More sharing options...
almightyegg Posted July 30, 2007 Author Share Posted July 30, 2007 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 More sharing options...
hitman6003 Posted July 30, 2007 Share Posted July 30, 2007 change $i to $j in your SQL Link to comment https://forums.phpfreaks.com/topic/62561-solved-while-loop/#findComment-311418 Share on other sites More sharing options...
almightyegg Posted July 30, 2007 Author Share Posted July 30, 2007 That sort of did it....Now instead, I have: Rank | Society 1-25 | 10 1-25 | 10 1-25 | 10 1-25 | 11 1-25 | 11 1-25 | 11 There's 3 lots of it.......eh? Link to comment https://forums.phpfreaks.com/topic/62561-solved-while-loop/#findComment-311421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.