Solved

PHP Code Question (Displaying of Data)

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Formating field inside mysql query 2 32
PHP: Filling Out/Creating a PDF 29 107
Duplicated data in GROUP_CONCAT 2 23
How to use session variables in php? 22 51
This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

726 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