BruceyBandit
BruceyBandit

Reputation: 4324

How do you concatenate two database fields together in PHP?

Below is my code:

while ($row = mysql_fetch_array($result)) {
      echo "
  <tr>
      <td>{$row['TeacherForename'].$row['TeacherSurname']}</td>
       <td>{$row['StudentForename'].$row['StudentSurname']}</td>
  </tr>";
    }

I want TeacherForname and TeacherSurname to concatenate with each other and StudentForename and StudentSurname and when I researched it says use the . syntax to concatenate but it doesn't work.

How are you suppose to do it?

Upvotes: 0

Views: 1039

Answers (1)

zerkms
zerkms

Reputation: 254906

while ($row = mysql_fetch_array($result)) {
      echo "
  <tr>
      <td>{$row['TeacherForename']}{$row['TeacherSurname']}</td>
       <td>{$row['StudentForename']}{$row['StudentSurname']}</td>
  </tr>";
    }

As long as you do that in the string context - . cannot be treated as php concatenation operator. So just place two variables together and that's it.

Upvotes: 1

Related Questions