-2

I want to be able too add this piece of code in a surrounded by an echo""

and stil be able to output the variables that is currently in the like below. This is where my mind is shutting down badly.

  <td><?php echo $row_Recordset1['leaveID']; ?>&nbsp; </td>
  <td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?>&nbsp; </a></td>
  <td><?php echo $row_Recordset1['rank']; ?>&nbsp; </td>
  <td><?php echo $row_Recordset1['organisation']; ?>&nbsp; </td>
  <td><?php echo $row_Recordset1['lastName']; ?>&nbsp; </td>
  <td><?php echo $row_Recordset1['firstName']; ?>&nbsp; </td>
  <td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>
pnuts
  • 58,317
  • 11
  • 87
  • 139
  • 4
    Welcome to Stack Overflow! It's best if your question title says something about the problem you're trying to solve.. That way the next person with a similar problem will be able to benefit from your question and any answers. Please consider editing your question to clarify the title. – O. Jones Nov 19 '15 at 11:36
  • I would suggest using an heredoc - You can read about it in the PHP [Manual](http://php.net/manual/en/language.types.string.php) – Peter Nov 19 '15 at 11:41
  • 3
    Please don't vandalise your question. – DavidG Nov 19 '15 at 14:03
  • DavidG, what do you mean by vandalising my own question? – user3701575 Jan 26 '16 at 03:05

3 Answers3

6

You are in need of using ob_get_contents();

Your code will look like this.

<?php
ob_start();
?>

      <td><?php echo $row_Recordset1['leaveID']; ?>&nbsp; </td>
      <td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?>&nbsp; </a></td>
      <td><?php echo $row_Recordset1['rank']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['organisation']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['lastName']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['firstName']; ?>&nbsp; </td>
      <td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>

<?php
$output = ob_get_contents();
ob_end_clean();
echo $output;
?>
Pratik Soni
  • 2,498
  • 16
  • 26
0

In cases if you cannot use output buffering as @PratikSoni suggested, I would recommend looking up printf() or sprintf() functions for having formatted output.

Usage example:

$output .= sprintf("<td>%s&nbsp;</td>", $row_Recordset1['leaveID']);

This way you have it in a variable, and could do echo or whatever else you might need it for.

Community
  • 1
  • 1
kayess
  • 3,384
  • 9
  • 28
  • 45
-1

See if this works

<td><?php echo $row_Recordset1['leaveID']; ?>&nbsp; </td>
<td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?>&nbsp; </a></td>
<td><?php echo $row_Recordset1['rank']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['organisation']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['lastName']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['firstName']; ?>&nbsp; </td>
<td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>
lalibi
  • 3,057
  • 3
  • 33
  • 41