Jump to content


This topic is now archived and is closed to further replies.



Recommended Posts

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 :P

Is there a better way lol ?

Any help appreciated.
Thanks guys

Heres 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:


$result = mysql_query(
"SELECT usernames FROM users");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");

while ( $row = mysql_fetch_array($result) ) {

$displayall = $row["usernames"];

<?php echo("$displayall"); ?></td></tr>




Share this post

Link to post
Share on other sites
Here it goes, a solution. Maybe a bit ugly but it works:

// 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>';

echo '</table>';

Just create an array with the anmes and use the code above.

Share this post

Link to post
Share on other sites


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.