1

I want to modify my query results with css styles.

For example my code is

<?php
      $sql=mysql_query("SELECT * FROM database")
      or die(mysql_error());   
    while($row = mysql_fetch_array( $sql )) {

    Print "$row[Number].$row[Email],$row[Username]<br>";

    }
?>

And i got a style with times new roman

<style type="text/css">
.Stylize {
    font-family: "Times New Roman", Times, serif;
}
</style>

How can I assign the Stylize CSS class to the print $row[Number] output?

4 Answers 4

3

the simplest way to do so is printing the style into the code easy for printing separated messages not related to the design of the page :

 Print "<span style='font-family:Times New Roman, Times, serif;'> $row[Number].$row[Email],$row[Username]</span>";

other way is to add the CSS class name and add the CSS code in a separate tag useful if u are printing many things with common style so you can change the tag once rather than change all the messages css code :

<style type="text/css">
.Stylize {
    font-family: "Times New Roman", Times, serif;
}
</style>

php code :

<?php
      $sql=mysql_query("SELECT * FROM database")
      or die(mysql_error());   
    while($row = mysql_fetch_array( $sql )) {

    Print "<span class='Stylize'>$row[Number].$row[Email],$row[Username]<span>";

    }
?>

very basic yet it's a very useful best practice

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

Comments

1
  Print "<span class=\"Stylize\">$row[Number]</span>.$row[Email],$row[Username]<br>";

Comments

0

Wrap each line in an element with desired class. It might be more readable to apply the class to the parent, though.

<style>
    div.styleize p { font-family: "Times New Roman", Times, serif; }
</style>    

<div class="styleize"'>
    <?php ... Print "<p>$row[Number].$row[Email],$row[Username]</p>"; ..?>
</p>

Comments

0
Print "<p class=\"Stylize\">$row[Number]</p>.$row[Email],$row[Username]<br>";

1 Comment

Using p will cause text to be broken into two lines.

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.