rsammy Posted November 15, 2006 Share Posted November 15, 2006 i need to just display the initials of a doctors name - say if the doctor is John Smith, JS shud be displayed. this is my code:**************$query2="SELECT visit_mgr.visit_id, visit_mgr.visit_status, visit_mgr.visit_loc, visit_mgr.visit_pat_id, visit_mgr.visit_phy_id, Date_Format(visit_mgr.visit_date, '%m/%d/%Y') as date, phy_det.phy_fname, phy_det.phy_lname, pat_dgraphics.pat_first_name, pat_dgraphics.pat_last_name, Date_Format(pat_dgraphics.pat_dob, '%m/%d/%Y') as pat_birthday, pat_dgraphics.pat_sex, pat_dgraphics.pat_ssn, pat_dgraphics.pat_ID, diag.diag_diag, visit_mgr.client_id FROM visit_mgr, phy_det, pat_dgraphics, diag WHERE visit_mgr.visit_type like '%$select1%' AND phy_det.phy_id=visit_mgr.visit_phy_id AND visit_mgr.visit_pat_id=pat_dgraphics.pat_ssn AND phy_det.phy_fname like '%$search3%' AND phy_det.phy_lname like '%$search4%' AND pat_dgraphics.pat_first_name like '%$search1%' AND pat_dgraphics.pat_last_name like '%$search2%' AND pat_dgraphics.pat_ssn like '%$search5%' AND diag.diag_visit_id=visit_mgr.visit_id AND diag.diag_patid=pat_dgraphics.pat_ID AND visit_mgr.client_id $clientid AND visit_date <= '$dates' AND visit_date >= '$datez' ORDER BY $select2 $select"; $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=\"center\">"); 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>"); } }****************how can i accomplish that in this code?thanks in advance Quote Link to comment Share on other sites More sharing options...
fert Posted November 15, 2006 Share Posted November 15, 2006 [code]$name=explode(" ",$name);$name1=explode("",$name[0]);$name2=explode("",$name[1]);$inits=$name1[0];$inits.=$name2[0];[/code] Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 15, 2006 Share Posted November 15, 2006 Or[code]<?php$name = "John Smith";list($first, $last) = sscanf($name, "%s%s");echo $first[0] . $last[0]; // Output: JS?>[/code] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Share Posted November 15, 2006 or just create a new field and record it first thing would be easier.Because either of these method's are great, but what if they have 3 names.Like for there first name they putJoyel Westmy middle name's areWest LeeJoyel West Lee Puryearsay I put west lee after joyel, then how is your program goign to cut that up, it won't.See what I mean, you have to accont for that as well. Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 15, 2006 Share Posted November 15, 2006 [quote author=businessman332211 link=topic=115083.msg468454#msg468454 date=1163613847]my middle name's areWest LeeJoyel West Lee Puryearsay I put west lee after joyel, then how is your program goign to cut that up, it won't.See what I mean, you have to accont for that as well.[/quote]ex:[code=php:0]$name = "Joyel West Lee Puryear";echo preg_replace('/(\w)\w+ ?/', "\\1", $name);[/code] Quote Link to comment Share on other sites More sharing options...
rsammy Posted November 15, 2006 Author Share Posted November 15, 2006 thanx for ur replies guys. but ill need some spoon feeding here. i wud like to show the first and last name initials for phy_fname and phy_lname in the code above! how do i do that. im not too comfortable with php yet! Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 15, 2006 Share Posted November 15, 2006 [code]<?php$word = "John Smith";$nword = explode(" ",$word);foreach($nword as $letter){ echo $letter{0};}?>[/code] Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 15, 2006 Share Posted November 15, 2006 Try adding this function to the beginning of the file:[code]function initials($name){ $nword = explode(" ",$name); foreach($nword as $letter){ $new_name .= $letter{0}; } return $new_name;}[/code]Next... Replace this code:[code] $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=\"center\">"); 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>");[/code]With this code:[code] $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=\"center\">"); print($row->initials(phy_fname)); print(" "); print($row->initials(phy_lname)); print("</div></td>"); $client_id=($row->client_id); print("<td height=\"14\"> <div align=\"center\">"); print($row->date); print("</div></td>");[/code]Tell us if it works. Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 15, 2006 Share Posted November 15, 2006 [quote author=rsammy link=topic=115083.msg468540#msg468540 date=1163620552]i wud like to show the first and last name initials for phy_fname and phy_lname in the code above! how do i do that. im not too comfortable with php yet![/quote]ex[code=php:0]print($row->phy_fname[0] . $row->phy_lname[0]);[/code] Quote Link to comment Share on other sites More sharing options...
rsammy Posted November 16, 2006 Author Share Posted November 16, 2006 thanx for ur replies guys! really appreciate ur help. little guy and nicklas - both ideas work! thanx!!!!!!!!! Quote Link to comment 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.