Hi Mate, Im having problem displaying data from database using loop. i need to put all even numbers to the left and odd numbers to the right. so if i have one page it should display 2,1,4,3 instead of 1,2,3,4 and so on.. attached is the output i want to come up. Cheers! Neil
Something like this in your loop will do the trick: if ($number % 2 == 0) { echo "<span class='pull-left'>$number</span>"; } PHP: You will need to work with layout/CSS for yourself, but hope you get the main idea.
Following could ve one solution to your problem. <html> <body> <?php $array=[1,2,3,4,5]; echo '<div style="position: absolute;left: 2px; width: 250px;">'; foreach($array as $value) { if($value%2==0) echo $value.'</br>'; } echo '</div>'; echo '<div style="position: absolute;left: 255px; width: 250px;">'; foreach($array as $value) { if($value%2!=0) echo $value.'</br>'; } echo '</div>'; ?> </html> Code (markup): you can retrieve the even and odd values directly from database : here is the query: SELECT values FROM table where values %2=0;
Output them in normal order in DIV with a wrapping DIV. <div class="reversed"><div>1</div><div>2</div><div>3</div><div>4</div></div> .reversed { position:relative; overflow:hidden; } /* make sure width is reported, wrap floats */ .reversed div { float:right; width:50%; } done. You don't even need fancy logic server-side. Flex-box's row-reverse could also fix this, or the DIR attribute in the markup could also be used. <div dir="rtl"><div>12</div><div>34</div></div> Though beware UTF-8 encoding screws with that, so under UTF-8 use the reverse direction character instead of DIR... I forget offhand what character that is. -- edit -- forget that last part about rtl/ltr. I can't seem to get that working here which isn't ENTIRELY surprising. Bidirectional language support really shouldn't be used for this case anyways.