Skip to content
Advertisement

How to style echoed text?

I am trying to style the user, time and content. they only appear once the user has entered a comment into the website and so I cannot use <p> tags with inline CSS. any suggestions?

if ($result->num_rows != 0 )
{
    $row;
    while($row = $result->fetch_assoc())
    {
        echo("</br>");
        echo("User: ".$row['user']."</br>");
        echo("Time: ".$row['time']."</br>");
        echo("Message: ".$row['content']."</br>");


    }
} 
}

Advertisement

Answer

1- create a class in your css (i.e: myClass)

2- use echo like this: echo 'User: <span class="myClass">'.$row['user'].'</span></br>' ;

Edited:

html characters in php are like string! so you may concat them all like this:

echo '</br> 
      <div class="myClass">
        User: '.$row['user']
        .'</br> 
        Time: '.$row['time']
        .'</br>
        Message: '.$row['content']
      .'</div> </br>';
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement