Jump to content

Recommended Posts

i have a list of check boxes

im ordering it according to Amenity name ASC

im floating 2 divs (columns)side by side

 

how can i get the list to echo it according to ABC :

like this::?

 

A D

B E

C F

<?php 
             	echo '<div style="height:800px;" />';
             	foreach($amens as $amen) {
             		echo '<div style="float:left;padding-left: 2px;width:200px;"><input onclick="changedata(this)" type="checkbox" id="mm'.$amen['Amen_ID'].'" value="'.$amen['Amenity'].'" '.checkAmenity($id, $amen['Amenity']).' /><label style="padding-left:3px;" for="mm'.$amen['Amen_ID'].'">'.$amen['Amenity'].'</label></div>';

             	} 
			echo '</div>';
             	?>

Link to comment
https://forums.phpfreaks.com/topic/249219-how-to-order-lists-correctly-in-a-loop/
Share on other sites

assuming its already sorted, you can simply halve the count of the array, and have two loops to go through them for each div. like

$arr = array(however your array is made and sorted);

$midPoint = ceil(count($arr)/2);//ceil to make a int
echo "<div id="left">
for ($i = 0; $i < $midPoint; $i++){
echo $arr[$i];
}
echo "</div>";

echo "<div id="right">
for ($i = $midpoint; $i < count($arr); $i++){
echo $arr[$i];
}
echo "</div>";

 

obviously you would need to change the output in my example to match what you desire.

assuming its already sorted, you can simply halve the count of the array, and have two loops to go through them for each div. like

$arr = array(however your array is made and sorted);

$midPoint = ceil(count($arr)/2);//ceil to make a int
echo "<div id="left">
for ($i = 0; $i < $midPoint; $i++){
echo $arr[$i];
}
echo "</div>";

echo "<div id="right">
for ($i = $midpoint; $i < count($arr); $i++){
echo $arr[$i];
}
echo "</div>";

 

obviously you would need to change the output in my example to match what you desire.

 

thanks i'll try it out

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.