?
Solved

PHP Code Question (Displaying of Data)

Posted on 2013-01-16
3
Medium Priority
?
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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