Jump to content

Confused by my own logic...


marcushjortsberg

Recommended Posts

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:)

Link to comment
Share on other sites

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.

Link to comment
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.