Jump to content


Photo

initials


  • Please log in to reply
3 replies to this topic

#1 rsammy

rsammy
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 30 October 2006 - 06:09 PM

hi

how do i display just the initials on the form ... not the full name. if thename is John Smith, I need to just dsplay JS on the screen

Thanks

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 30 October 2006 - 06:18 PM

Suppose you always have the name in a variable. Are you wanting to use ALL provided names in the initials (including middle name, if provided)? If so, just use something like this:
<?php
function getInitials($name) {
  $init = '';
  $name = explode(' ', $name);
  foreach ($name as $part) $init .= strtoupper(substr($part,0,1));
  return $init;
}

$name = "John Smith";
echo getInitials($name); // outputs 'JS'

$name2 = "Wanda P. Oberholzer";
echo getInitials($name2); // outputs 'WPO'
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 rsammy

rsammy
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 30 October 2006 - 10:42 PM

thanx for replying obsidian! i still amconfused
my original code is like this:

$query2="SELECT **********from ***** where **********

$result=mysql_db_query("$database[dbname]", $query2);
$num_rows=mysql_num_rows($result);
$num_results=mysql_num_rows($result);

$i=1;
if(!isset($rowNum))
{
    $rowNum = 0;
}

$rowNumHold = $rowNum;
$count = 1;
$limit_results = 25;

if ($num_rows > 0)
{
    for($q=0;$q<$limit_results && $rowNum < $num_rows;$q++)
    {
if(mysql_data_seek($result, $rowNum++))
{
      if ($i++%2)
      {

print ("<tr  bgcolor=\"#cccccc\">");
      }
    else
{
      print ("<tr>");
}

$row = mysql_fetch_object($result);

print("<td height=\"14\"> <div align=\"left\">");
            print($row->pat_last_name);
print(", ");
print($row->pat_first_name);

print("</div></td>");

print("<td height=\"14\"> <div align=\"center\">");
print($row->pat_birthday);
print("</div></td>");

print("<td height=\"14\"> <div align=\"center\">");
print($row->pat_ssn);
print("</div></td>");

print("<td height=\"14\"> <div align=\"left\">");
print($row->phy_fname);
print(" ");
print($row->phy_lname);
print("</div></td>");

$client_id=($row->client_id);
print("<td height=\"14\"> <div align=\"center\">");
print($row->date);
print("</div></td>");

print("<td height=\"14\"> <div align=\"center\">");
print ("<a href=\"Recorddetails.php?visit_id=$row->visit_id&visit_type=ICN&client_id=$row-
                      >client_id&visit_status=$row->visit_status&visit_loc=$row-
                      >visit_loc&pat_first_name=$row->pat_first_name&pat_last_name=$row-
                      >pat_last_name&phy_fname=$row->phy_fname&phy_lname=$row-
                      >phy_lname&pat_dob=$row->pat_birthday&pat_ssn=$row-
                      >pat_ssn&pat_sex=$row->pat_sex\">Details</a>");
print("</div></td>");


print("</tr>");
      }

}

*********

now if you look at phy_lname and phy_fname - thats where i need to use initials in place of full phycians full name. also i need to pass the same stuff to the next page - recorddetails.php

how would i be able to do that?

help will be greatly appreciated
thanx

#4 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 31 October 2006 - 03:19 PM

declare obsdian's function and
use print(getInitials($row->pat_first_name));




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users