Jump to content

Spaces in Listbox


romay

Recommended Posts

Hello all,

 

I am new here and fairly new to PHP so please bear with me. Here is my situation I have a Listbox being populated from a MySQL database loading last name. first name, user name, and user level which works great. Here is what I am trying to do now, I would like everything spaced out evenly for ease of use explample:

 

What it shows in the list box now is

LastnameFirstnameUsernameUserlevel (this is all together with no spaces)

 

what I would like it to show is:

Lastname      Firstname      Username      Userlevel

 

I have tried using &nbsp and a couple of other things but to no avail

here is the code that I am using:

 

$query = "SELECT * FROM security";

$result = mysql_query($query);

// print "<SELECT name= 'Listbox1' Class='purplebox'>";

print "<OPTION value='$security'"; //This row loading the option previously selected

print ">$security</OPTION>"; //This too, if it is not an update you dont need these two

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

echo "<OPTION value='".$row['security']."'>­ ".$row['last_name'],$row['first_name'],$row['username'],$row['userlevel'] .'</OPTION>';

}

?>

</select>

 

I have googled the quite a bit but found nothing that worked

Any help will be greatly appreciated,

 

 

Link to comment
Share on other sites

Thank you so much for your help, it was driving me crazy. One more question lets say I have a username that contains 20 characters and one that say contains 5 characters, I would like to have the userlevel all lined up could you point me in the right direction to start with. I am thinking I will have to use some type of LEN command to add the 5 with 15 spaces so every thing will be even and lined up. If this is not correct could you tell me the command I may have to use.

 

Thanks Again,

Romay

Link to comment
Share on other sites

Hello all,

 

  Here is a change I made to try and make all data line up but this is not working not sure why though,

 

$padded_last_name = str_pad($row['last_name'], 20);   

$padded_first_name = str_pad($row['first_name'], 20);

$padded_user_name = str_pad($row['username'], 10);

$padded_user_level = str_pad($row['userlevel'], 10);

 

echo "<OPTION value=\"".$row['security']."\">­".$padded_last_name." ".$padded_first_name." ".$padded_user_name." ".$padded_user_level."</OPTION>";

 

 

Thanks Again.

Link to comment
Share on other sites

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.