romay Posted June 19, 2008 Share Posted June 19, 2008 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   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, Quote Link to comment https://forums.phpfreaks.com/topic/110973-spaces-in-listbox/ Share on other sites More sharing options...
ober Posted June 19, 2008 Share Posted June 19, 2008 echo "<OPTION value=\"".$row['security']."\">".$row['last_name']." ".$row['first_name']." ".$row['username']." ".$row['userlevel']."</OPTION>"; Quote Link to comment https://forums.phpfreaks.com/topic/110973-spaces-in-listbox/#findComment-569333 Share on other sites More sharing options...
romay Posted June 20, 2008 Author Share Posted June 20, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110973-spaces-in-listbox/#findComment-570478 Share on other sites More sharing options...
romay Posted June 20, 2008 Author Share Posted June 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/110973-spaces-in-listbox/#findComment-570552 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.