Gowtham Gowtham - 3 months ago 7
PHP Question

where to enter "&nbsp" in the following code?

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);
?>

Answer

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>';