Horizontal Results from MySQL using PHP

Below is the code I am using to populate a menu with check boxes. I need to adjust the code so that it will display 5 results horizontally then <br> and then the next 5 will display horizontally under the first 5 and so on. The code I am using works perfectly but it displays all results vertically..
/////////////////////////////////////////////////////////////////////////////////////;



  function chk_box_qry($id,$sel,$ncr_id) {
     // create check box list from database;


	//query for options

	$qry= my_query('

			SELECT 
		  		op.id			AS id,
				op.num			AS num,
				op.ois_id		AS ois_id,
				ncr_ref.ncr_id		AS ncr_id
				
				
		FROM	op 	AS op
		LEFT JOIN ncr_ref AS ncr_ref ON ncr_ref.op_id=op.id
		WHERE op.cdr_id = '.$id.'
		ORDER by op.num;
		
		

		');





      //Puts results into a checkbox format, (id as the recorded value);



while($row = mysql_fetch_assoc($qry)) { 

                if ($row['ncr_id'] == $ncr_id) { 
 
                        $ch='checked'; 
 
                } else { 
 
                        $ch=''; 
 
                } 
 
        $chkbox .=  'OP&nbsp;'. $row['num'] . '&nbsp;<input type="hidden" name="ncr_ref:id:' . $row['id'] . '" value="'.$row['ncr_id'].'">
		
		<input type="hidden" name="ncr_ref:op_id:' . $row['id'] . '">
		
		<input type="checkbox" '.$ch.'  name="ncr_ref:op_id:' . $row['id'] . '"  value="' . $row['id'] . '">
		
		<input type="hidden" name="ncr_ref:ncr_id:'.$row['id'].'" value="' . $ncr_id . '"><br>' ; 
		     
        }


	return $chkbox;
  }

Open in new window

brad0525Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brad0525Author Commented:
I am displaying the results on another page using the code below..
<tr>
			<td colspan=20 style="text-align:left; height: 150;">
			<div style="overflow:auto; height:100%; text-align:left;">
				'.chk_box_qry($row['cdr_id'],$row['ois_id'], $row['ncr_id'], $row['ncr_ref_id']).'
				</div>
			</td>
		</tr>

Open in new window

0
john-formbyCommented:
Hi,

Please have a look at the following simple example showing how to split checkboxes over several lines.

Hope this helps,

John
<?php
$i = 0;
$x = 0;
while($i <= 16) {
	$i++;
	$x++;
	echo '<input type="checkbox" name="cbox[]" />';
	if($x == 5) {
		echo '<br />';
		$x = 0;
	}
}
?>

Open in new window

0
titzu2001Commented:
Hi,
I modified your function and should work.

/////////////////////////////////////////////////////////////////////////////////////;



  function chk_box_qry($id,$sel,$ncr_id) {
     // create check box list from database;


	//query for options

	$qry= my_query('

			SELECT 
		  		op.id			AS id,
				op.num			AS num,
				op.ois_id		AS ois_id,
				ncr_ref.ncr_id		AS ncr_id
				
				
		FROM	op 	AS op
		LEFT JOIN ncr_ref AS ncr_ref ON ncr_ref.op_id=op.id
		WHERE op.cdr_id = '.$id.'
		ORDER by op.num;
		
		

		');





      //Puts results into a checkbox format, (id as the recorded value);


$rowIndex = 0;
	
while($row = mysql_fetch_assoc($qry)) { 

                if ($row['ncr_id'] == $ncr_id) { 
 
                        $ch='checked'; 
 
                } else { 
 
                        $ch=''; 
 
                } 
 
        $chkbox .=  'OP&nbsp;'. $row['num'] . '&nbsp;<input type="hidden" name="ncr_ref:id:' . $row['id'] . '" value="'.$row['ncr_id'].'">
		
		<input type="hidden" name="ncr_ref:op_id:' . $row['id'] . '">
		
		<input type="checkbox" '.$ch.'  name="ncr_ref:op_id:' . $row['id'] . '"  value="' . $row['id'] . '">
		
		<input type="hidden" name="ncr_ref:ncr_id:'.$row['id'].'" value="' . $ncr_id . '">' ; 
        
		$rowIndex++;     
        if ($rowIndex==4) {
        	$chkbox .='<br>';
        	$rowIndex = 0;
        }
        
        
        }
        

		
			
	return $chkbox;
  }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.