Solved

PHP Code Question (Displaying of Data)

Posted on 2013-01-16
3
403 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:
RQuadling 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now