web_master Posted June 15, 2008 Share Posted June 15, 2008 hi, is some possibility to flow text in 2 columns (or more) with php (from dbase) like do in printed newspaper? thnx [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/110318-solved-flow-text-in-2-or-more-column/ Share on other sites More sharing options...
webbiedave Posted June 15, 2008 Share Posted June 15, 2008 This is a function of HTML/CSS, not PHP. Try googling: two column css Quote Link to comment https://forums.phpfreaks.com/topic/110318-solved-flow-text-in-2-or-more-column/#findComment-566009 Share on other sites More sharing options...
Sulman Posted June 15, 2008 Share Posted June 15, 2008 Here's a little script I wrote a while ago for doing just that: <?php $count=1; $number_of_columns=2; //The required number of columns while ($rowWork = mysql_fetch_array($resultWork)){ if ($count==1){ echo "<tr>"; //Open the row } echo '<td valign="top">$row['column']</td>'; if ($count==$number_of_columns){ echo "</tr>"; //Close the row if we have reached the required number of columns $count=0; //Set the counter back } $count++; } ?> [Edit] This is for display images etc over 2 columns but you should be able to modify it easly for text Quote Link to comment https://forums.phpfreaks.com/topic/110318-solved-flow-text-in-2-or-more-column/#findComment-566011 Share on other sites More sharing options...
.josh Posted June 15, 2008 Share Posted June 15, 2008 well..I suppose you could like, query your db, get the text, split it up and all that...but yeah, that's not really the point of php.... Quote Link to comment https://forums.phpfreaks.com/topic/110318-solved-flow-text-in-2-or-more-column/#findComment-566015 Share on other sites More sharing options...
Barand Posted June 15, 2008 Share Posted June 15, 2008 another way: <?php $str = file_get_contents('lorem ipsum.txt'); $p = floor(strlen($str)/2); $p = strpos($str, ' ', $p); // find a space in middle of the text echo '<div style="float:left; width:45%; padding: 0 10px">', nl2br(substr($str, 0, $p)), '</div>'; echo '<div style="float:left; width:45%; padding: 0 10px">', nl2br(substr($str, $p+1)), '</div>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/110318-solved-flow-text-in-2-or-more-column/#findComment-566019 Share on other sites More sharing options...
web_master Posted June 15, 2008 Author Share Posted June 15, 2008 another way: <?php $str = file_get_contents('lorem ipsum.txt'); $p = floor(strlen($str)/2); $p = strpos($str, ' ', $p); // find a space in middle of the text echo '<div style="float:left; width:45%; padding: 0 10px">', nl2br(substr($str, 0, $p)), '</div>'; echo '<div style="float:left; width:45%; padding: 0 10px">', nl2br(substr($str, $p+1)), '</div>'; ?> Barand, great! thnx!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/110318-solved-flow-text-in-2-or-more-column/#findComment-566056 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.