-1

Can some one kindly help me find a place to add &nbsp between each of the rows in the echo statement. where and how can I add blank space between each row? kindly ignore the first set of echo statements that have been commented out. Thank you...

<link rel="stylesheet" href="docfullcss.css"> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'employee_info'; $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); if(! $conn ) { die('Could not connect: ' . mysqli_connect_error()); } $sql = 'SELECT * FROM `docfull` ORDER BY `COL 7` ASC'; $retval = mysqli_query($conn,$sql); if(! $retval ) { die('Could not get data: ' . mysqli_error($conn)); } while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { /* (ignore this commented section) echo "<table>"; echo "<tr>"; echo "<td>COL 1</td>"; echo "<td>COL 2</td>"; echo "</tr>"; echo "</table>"; */ echo "<tr><td>" . $row['COL 1'] . "</td> <td>" . $row['COL 2'] . "</td> </tr>" . $row['COL 3'] . "</td> <td>" . $row['COL 4'] . "</td> <td>" . $row['COL 5'] . "</td> <td>" . $row['COL 6'] . "</td> <td>" . $row['COL 7'] . "</td> <td>" . $row['COL 8'] . "</td> <td>" . $row['COL 9'] . "</td> <td>" . $row['COL 10'] . "</td> <td>" . $row['COL 11'] . "</td> <td>" . $row['COL 12'] . "</td> <td>" . $row['COL 13'] . "</td> <td>" . $row['COL 14'] . "</td> <td>" . $row['COL 15'] . "</td> <td>" . $row['COL 16'] . "</td><td>"; echo "<br><br>"; } mysqli_close($conn); ?> 
6
  • 1
    There is no need of &nbsp between tr, They automatically adjust themselves. Commented May 23, 2016 at 6:04
  • How you do add table row after closing the table? Commented May 23, 2016 at 6:05
  • use <table cellspacing="5" cellpadding="5" > for automatically spacing between TR and TD Commented May 23, 2016 at 6:05
  • Possible duplicate of this question Commented May 23, 2016 at 6:08
  • you should consider usage of a template engine to avoid such messy code... Commented May 23, 2016 at 6:12

1 Answer 1

1

Problem is here

echo "<tr><td>" . $row['COL 1'] . "</td><td>" . $row['COL 2'] . "</td></tr>" . $row['COL 3'] . 

You end row after COL 2 and never start again till another iteration. You need to remove this </tr> after COL 2 and add <td> to this place and add </tr> after . $row['COL 16'] . "</td><td>"; , also you don'd need last td and those <br> tags on next line.

To have simple table you need something like this:

echo '<table>'; while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { echo "<tr><td>" . $row['COL 1'] . "</td> <td>" . $row['COL 2'] . "</td> <td>" . $row['COL 3'] . "</td> <td>" . $row['COL 4'] . "</td> <td>" . $row['COL 5'] . "</td> <td>" . $row['COL 6'] . "</td> <td>" . $row['COL 7'] . "</td> <td>" . $row['COL 8'] . "</td> <td>" . $row['COL 9'] . "</td> <td>" . $row['COL 10'] . "</td> <td>" . $row['COL 11'] . "</td> <td>" . $row['COL 12'] . "</td> <td>" . $row['COL 13'] . "</td> <td>" . $row['COL 14'] . "</td> <td>" . $row['COL 15'] . "</td> <td>" . $row['COL 16'] . "</td></tr>"; } echo '</table>'; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.