Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drop down align

Status
Not open for further replies.

techris

Programmer
Apr 2, 2007
8
US
I have built a drop down menu that is populated from an sql database. Each <option> includes 2 variables. I need to align each variable.

This example won't work, but illustrates what I am trying to do:
Code:
<option value="value"><table><tr><td align="left">value1</td><td align="left">value2</td></tr></table></option>

I built a php script that counts the first variable name and adds &nbsp; until it reaches 30 characters in length and then echos the second variable. My problem is that not all characters in the font are the same width so the results end up misaligned, but closer. Any ideas?

current function:

Code:
function theaccts() {
	
	$table = "accounts";

	$conn = mysql_connect("$host", "$user", "$passwd");
	mysql_select_db("$thedb", $conn);
	
	$sql = "SELECT * FROM $table ORDER BY 'name'";
	
	$result = mysql_query($sql, $conn);
		$fields = mysql_num_fields ($result);
		$rows   = mysql_num_rows ($result);
	
			$g='0';
	
		while ($row = mysql_fetch_object ($result)) {
				for ($i = 0; $i < $fields; $i++) {
					  $fname = mysql_field_name($result, $i);
					  
					  if ($fname == 'ID') {
					  $id[$g] = $row->$fname;
					  
					  } else if ($fname == 'type') {
				 	  $type[$g] = $row->$fname;			
					  
					  } else if ($fname == 'name'){
					  $name[$g] = $row->$fname;
			  
					  }
				} // end for
				
##############  add spaces to the name  ##########
		
for ($i='0'; $i<'30'; $i++) {
$a[$i] = substr($name[$g], $i, 1);

	if ($a[$i] == NULL) {
		$a[$i] = "&nbsp; ";
	
	}
	
	$name1[$g] .= $a[$i];

}
	
##################################################
				
			$g++;
		} // end while
		
		
		
	$typesort = array("red", "black", "yellow", "orange", "peuce", "brown", "purple", "pink", "green", "magenta", "tan");
		
			$p='0';
		while ($p<'11'){
	
			for ($z='0'; $z<count($id); $z++) {
			
				if ($type[$z] == $typesort[$p]) {
					echo "<option value=\"".$name[$z]."\">".$name1[$z]." &nbsp; &nbsp; &nbsp; $type[$z] </option>";
		
				}
		
			} // end for
		
			$p++;
	
		} // end while

} // end function

Thanks in advance!
 
Use a monospaced font, where all the characters are of equal width. You can specify the font via the CSS. Popular monospaced fonts include Courier (New), Terminal and Lucida Console but every computer should have one, so if you specify monospace it will find the appropriate one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top