BaconBeast321 Posted May 28, 2006 Share Posted May 28, 2006 Hello again, wow these forums are great! I have a variable $usernames that contains the array of all the current usernames in the DB, (quite a few). The problem is when I echo this list onto a page, it scatters the names downwards and ruins the feel of the site. (as you can imagine).I want to be able to display these usernames tidily with 5 or so per row in a table, the only way I can think of doing this is to SELECT just one username and display and repeat the process until like 999 :PIs there a better way lol ?Any help appreciated.Thanks guysHeres the website: [a href=\"http://www.lifenz.com/phppractice/setperm.php\" target=\"_blank\"]http://www.lifenz.com/phppractice/setperm.php[/a]And heres the script:<?php $result = mysql_query( "SELECT usernames FROM users"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } while ( $row = mysql_fetch_array($result) ) { $displayall = $row["usernames"];?><tr><TD><?php echo("$displayall"); ?></td></tr><?php }?> Link to comment https://forums.phpfreaks.com/topic/10627-help-with-select-and-echo-result/ Share on other sites More sharing options...
poirot Posted May 28, 2006 Share Posted May 28, 2006 Here it goes, a solution. Maybe a bit ugly but it works:[code]<?php// This is just to generate an array with fruits. $str = 'apple strawberry watermelon orange pineapple banana cheery grape peach';$fruits = explode(' ', $str);// Define number of cells per row$per_row = '1';echo '<table>';$i = 0;while ($i<count($fruits)) { for ($j=0; $j<$per_row; $j++) { if ($j==0) { echo '<tr>'; } echo '<td>' . $fruits[$i] . '</td>'; if ($j==$per_row) { echo '</tr>'; } $i++; }}echo '</table>';?>[/code]Just create an array with the anmes and use the code above. Link to comment https://forums.phpfreaks.com/topic/10627-help-with-select-and-echo-result/#findComment-39632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.