Jump to content

Archived

This topic is now archived and is closed to further replies.

rsammy

initials

Recommended Posts

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

Share this post


Link to post
Share on other sites
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:
[code]
<?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'
?>
[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
declare obsdian's function and
use print(getInitials($row->pat_first_name));

Share this post


Link to post
Share on other sites

×

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.