Solved

PHP Code Question (Displaying of Data)

Posted on 2013-01-16
3
404 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

920 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

14 Experts available now in Live!

Get 1:1 Help Now