0

I want to display forloop value in newline in html table

echo "<tr>";
echo "<td>".$i++."</td>";
echo "<td>".$row['instructorname']."</td>";
echo "<td>".$row['batchname']."</td>";
echo "<td>".$row['fromdate']."</td>";
echo "<td>".$row['todate']."</td>";

for ($i = $startdate; $i < $todate; $i++) echo '<td>'.$i.'</td>';
echo "</tr>";

I want to display each $i value in newline but it appears in same line.

2
  • if you need all value in same td then use this echo '<td>'; for($i=$startdate;$i<$todate;$i++){ echo $i.'\n' ;} echo '</td>'; Commented Jun 1, 2019 at 6:02
  • you can use <br> tag Commented Jun 1, 2019 at 6:05

2 Answers 2

1

Just echo <br/> to make a new line

echo '<td>', $startdate;

for($i = $startdate + 1; $i < $todate; $i++)
    echo '<br/>', $i;

echo '</td>';

FYI use comma in echo statement is better than dot

Sign up to request clarification or add additional context in comments.

Comments

0

Just added in your code

concat "\n" to the front of the statement

echo "\n" ."<td>" . $row['instructorname'] . "</td>";
echo "\n" ."<td>" . $row['batchname'] . "</td>";

I hope it's helps you.

Thank you.

1 Comment

If you are going to use "\n" for some reason better use PHP_EOL constant because on different system new line character can be different. For example also "\r" and PHP_EOL already have character suitable for your current system

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.