whynot Posted January 1, 2012 Share Posted January 1, 2012 Hi, Mary Christmas My result of mysql database is LIMIT 8; now i have to retrieve and show this to two Horizontal columns As each columns 4 result. how to generate this Without tables!! only with DIV or UL/LI list . Thanks Quote Link to comment https://forums.phpfreaks.com/topic/254179-two-result-in-two-horizontal-columns-without-table/ Share on other sites More sharing options...
AyKay47 Posted January 1, 2012 Share Posted January 1, 2012 The short simple explanation, in a while loop, set an incrementing variable, if the variable is a modulus of 4, create another <ul> to fill with <li>. Quote Link to comment https://forums.phpfreaks.com/topic/254179-two-result-in-two-horizontal-columns-without-table/#findComment-1303170 Share on other sites More sharing options...
whynot Posted January 1, 2012 Author Share Posted January 1, 2012 i create while loop But I'm not sure how to act Quote Link to comment https://forums.phpfreaks.com/topic/254179-two-result-in-two-horizontal-columns-without-table/#findComment-1303171 Share on other sites More sharing options...
AyKay47 Posted January 2, 2012 Share Posted January 2, 2012 can you post the code that you have, will make it easier for me to help. Quote Link to comment https://forums.phpfreaks.com/topic/254179-two-result-in-two-horizontal-columns-without-table/#findComment-1303187 Share on other sites More sharing options...
jcbones Posted January 2, 2012 Share Posted January 2, 2012 <?php $i = 0; //set variable I as 0 echo '<div style="float:left;">'; //start a division. while($row = mysql_fetch_assoc($result)) { //fetch the data. if(++$i == 5) { //if $i has passed 4 which means 4 lines have been printed, close the division and open another. echo '</div><div>'; } echo implode(',<br />',$row); //echo the data. } echo '</div>'; //close the final division. Quote Link to comment https://forums.phpfreaks.com/topic/254179-two-result-in-two-horizontal-columns-without-table/#findComment-1303399 Share on other sites More sharing options...
whynot Posted January 3, 2012 Author Share Posted January 3, 2012 I wirte this code for 4 * 4 : echo "<div><ul>"; $c = 1; $media = mysql_query("SELECT * FROM " . "$prefix" . "screen where id=\"$id\" order by id desc limit 16"); while ($cms = mysql_fetch_assoc($media)) { if (!($c%4)) echo ($c!=0 ? "</ul>" : "")."<ul>"; echo "<li><a href=\"#\"><img src=\"#\"></a></li>\n"; $c++; } echo "</ul></div>\n"; for ($cnt=$c;$cnt%4>0;$cnt++); ?> Html output is : <UL> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> </UL> <UL> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> </UL> <UL> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> </UL> <UL> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> <li><a href=\"#\"><img src=\"#\"></a></li> </UL> <UL> <li><a href=\"#\"><img src=\"#\"></a></li> </UL> This is false . actually i need to each <UL> 4 <LI> . What's problem ! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/254179-two-result-in-two-horizontal-columns-without-table/#findComment-1303521 Share on other sites More sharing options...
jcbones Posted January 3, 2012 Share Posted January 3, 2012 The problem is that you are not communicating what you are looking for very well. Can you give us an example of your expected output? Quote Link to comment https://forums.phpfreaks.com/topic/254179-two-result-in-two-horizontal-columns-without-table/#findComment-1303922 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.