marcushjortsberg Posted February 24, 2012 Share Posted February 24, 2012 I make a query where I fetch som individuals and group them by class and count the rows. I make a for statement and in that statement I make a new query where I fetch all individuals in each class and sort them by id. Each member in each class should be printed into a file, limited by 15, if there is more than 15 the rest should be printed to the next file. My logic is a little confusing to me... $queryorder = "SELECT * FROM mytable GROUP BY class ORDER BY cat_order"; count $rows1... for ($ii = 0; $ii < $rows1; $ii++) { $query = "SELECT * FROM mytable WHERE class = '". $rows1[$ii]['class'] . "' ORDER BY id"; $rows2 $count = 1; $sid_nr = 1; $list_nr = 1; for ($iii = 0; $iii < $rows2; $iii++) { if($count == 1) { createnewfile $ring = $rows2[$iii]['ring']; } for($count_i = 1; $count_i < 16; $count_i++): if($rows2[$iii]['C'] == 1){$rows2[$iii]['C'] = 'C';}else{$rows2[$iii]['C'] = '';} if($rows2[$iii]['S'] == 1){$rows2[$iii]['S'] = 'S';}else{$rows2[$iii]['S'] = '';} if($count_i == $count) { variabel1='VAR1'.$count_i, $rows2[$iii]['nr']); variabel2='CS'.$count_i, $rows2[$iii]['C'] . $rows2[$iii]['S']); variabel3='NAME'.$count_i, $rows2[$iii]['id_nr'] . ' ' . $rows2[$iii]['name']); } endfor; $count++; if($count == 15) { $filename = somefilename; $myFile = $resultiddir.DS.$filename; closefile $count = 1; $sid_nr++; } if($count == $rows2 { $filename = somefilename; $myFile = $resultiddir.DS.$filename; closefile $count = 1; $sid_nr = 1; } } } Some of it is pseudocode but the idea is the important thing:) Quote Link to comment https://forums.phpfreaks.com/topic/257663-confused-by-my-own-logic/ Share on other sites More sharing options...
silkfire Posted February 24, 2012 Share Posted February 24, 2012 Make your two loops. In the inner loop, add all members to an array $members. Then use the awesome function array_chunk (array_chunk($members, 15)) that will split the array into equal parts of 15, leaving the last array with 15 or less members. Then run a foreach on this array and add all members to the text file. Quote Link to comment https://forums.phpfreaks.com/topic/257663-confused-by-my-own-logic/#findComment-1320720 Share on other sites More sharing options...
marcushjortsberg Posted February 24, 2012 Author Share Posted February 24, 2012 HI! Thanx for the reply, sounds promising:) Is it a typo to run the array_chunk twice as array_chunk (array_chunk($members, 15)) or is it what I should do? If so, could you explain what happens with this double array_chunk? Quote Link to comment https://forums.phpfreaks.com/topic/257663-confused-by-my-own-logic/#findComment-1320738 Share on other sites More sharing options...
silkfire Posted February 24, 2012 Share Posted February 24, 2012 It's not double I just showed you in the paranthesis how the syntax goes. Use it like that =P Quote Link to comment https://forums.phpfreaks.com/topic/257663-confused-by-my-own-logic/#findComment-1320760 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.