abcd abcd - 28 days ago 8
PHP Question

display static values inside table in php while

We are using below code to display table , here id , name , email are not displaying inside table , but i wanted to include those inside table

enter image description here

PHP + html

$c1 = $c2 =$c3 = "";
while($data = $stmt->fetch())
{
$c1 .= "<td> {$data['userID']} </td>" ;
$c2 .= "<td> {$data['name']} </td>";
$c3 .= "<td> {$data['email']} </td>";
}
echo "<table>
<tr> ID $c1</tr>
<tr> name $c2</tr>
<tr> email $c3</tr>
</table>";


css

tr { display: block; float: left; }
th, td { display: block; }
.table, th, td
{
border: 1px solid black;
color : blue;
padding: 10px;
}


I tried this code too , but still same result :
$c1 .= " ID2 <td> {$data['userID']} </td>" ;


Note: I really tried too much before posting question....

Answer

Here's what you code should be:

echo "<table>";
echo "<tr>
    <td>id</td>
    <td>name</td>
    <td>email</td>
</tr>";
while($data = $stmt->fetch())
{ 
    echo "<tr>
        <td>" . $data['userID'] . "</td>
        <td>" . $data['name'] . "</td>
        <td>" . $data['email'] . "</td>
    </tr>";
}
echo "</table>";