Page 1 of 1

Help with display length

Posted: Fri Jun 25, 2004 6:29 pm
by mattmcb
Can someone help me out with setting the display length for this code:

Code: Select all

<?php
	while ($row_send = mysql_fetch_array($result_send))
	{    
		echo ('<option value="'.$row_send['user_id'].'">'.$row_send['username'].' | '.$row_send['storename'].' | '.$row_send['companyname'].'</option>');
		}

?>
Basically, three values are being pulled from the DB and used to create a dropdown liast for the user to select. I would only like to display the first 25 characters of each value; how do I do that? Even if the value is less then 25 characters I still want 25 characters to display so there would be blank spaces after the value.

Any help would be appreciated!

Posted: Fri Jun 25, 2004 6:43 pm
by feyd
not absolutely sure here but:

Code: Select all

<?php 

   function first25($string) { return str_replace(' ','&'.'nbsp;',sprintf("%25s",$string)); }
   while ($row_send = mysql_fetch_array($result_send)) 
   {    
      echo ('<option value="'.$row_send['user_id'].'">'.first25($row_send['username']).' | '.first25($row_send['storename']).' | '.first25($row_send['companyname']).'</option>'); 
      } 

?>
should be left aligned now.