Solved

PHP Code Question (Displaying of Data)

Posted on 2013-01-16
3
409 Views
Last Modified: 2013-10-07
Hello,
The following code displays some data from a MySQL database in a form on a web browser.

<td><?php echo "".$row['fname']; ?></td> 
<td><?php echo "".$row['lname']; ?></td>

Open in new window


fname represents the first name of a person & lname is the last name. CUrrently I have a column names "First Name" & one named "Last Name". My question is, if I create a column named "Client Name" & want to place the full name in it, how do I do that? Or in other words, how would I edit my code so it would show John Doe in the field as opposed to John in one field & Doe in another? Thanks
0
Comment
Question by:wantabe2
3 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 500 total points
ID: 38783985
Your current style.
<td><?php echo $row['fname'] . " " . $row['lname']; ?></td>

Open in new window


Using embedded variables. Note the use of "" around the entire string being echo'd. This forces PHP to process/look for variables.
<?php
echo "<td>{$row['fname']} {$row['lname']}</td>";

Open in new window


Using heredoc. No need for quotes, so they can be used in the text (<td class="name"> sort of thing.
<?php
echo <<< END_CLIENT_NAME
<td>{$row['fname']} {$row['lname']}</td>
END_CLIENT_NAME;

Open in new window

0
 
LVL 15

Author Closing Comment

by:wantabe2
ID: 38784053
Thanks!
0
 
LVL 1

Expert Comment

by:Joe_Pritchard
ID: 39553003
Here's how I would do it:

<?php
echo "<td>", trim($row['fname'] ." ".  $row['lname']), "</td>";
?>

Open in new window


No great difference, but you won't get rogue spaces in the case of anyone with no surname, or only a surname... Just a thought.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question