Jump to content

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:

<?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

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.