• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 627
  • Last Modified:

How to embed CSS in PHP?

Hi experts:

I have a HTML  CSS code code (as seen below) embedded in PHP.

But it is not working.  
Can you kindly give me a tip?

Thanks!

<? php
 
'<style type="text/css">
table.myTable td
{
  border: solid 1px black;
}
table.myTable th
{
  border: solid 1px black;
  background-color:silver;
}
</style>'
 
echo '<table class = "myTable"><tr><th> Name</th><th> Email</th></tr>';
 
    while (!$result->EOF)
    {
 
      echo '<tr>' .
      
          '<td>' . $result -> fields ['Name']. '</td>' .
          '<td>' . $result -> fields ['Email'] . '</td>' .
          '</tr>';

Open in new window

0
duta
Asked:
duta
  • 3
  • 2
2 Solutions
 
JoachimMartinsenCommented:
You need to echo out the CSS code.
0
 
Loganathan NatarajanLAMP DeveloperCommented:
try this,


<? php
 
echo '<style type="text/css">
table.myTable td
{
  border: solid 1px black;
}
table.myTable th
{
  border: solid 1px black;
  background-color:silver;
}
</style>';
 
echo '<table class = "myTable"><tr><th> Name</th><th> Email</th></tr>';
 
    while (!$result->EOF)
    {
 
      echo '<tr>' .
      
          '<td>' . $result -> fields ['Name']. '</td>' .
          '<td>' . $result -> fields ['Email'] . '</td>' .
          '</tr>';
		  
		  ?>

Open in new window

0
 
dutaAuthor Commented:
Thank you so much for your kind, prompt tip.

By the way, I  inserted "Echo" command. Still I got an error message from

the bottom line of the code (in Code Snippet box):


//  Errors comes from the line below

echo "<table class = 'myTable'><tr><th> Name</th><th> Email</th></tr>";
<?php
 
function printEntries($result)
{
 echo
"<style type='text/css'>
table.myTable td
{
  border: solid 1px black;
}
table.myTable th
{
  border: solid 1px black;
  background-color:silver;
}
</style>"
 
 
 
 
echo "<table class = 'myTable'><tr><th> Name</th><th> Email</th></tr>";

Open in new window

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Loganathan NatarajanLAMP DeveloperCommented:
oK,

<?php
 
function printEntries($result)
{
 
 echo
"<style type='text/css'>
table.myTable td
{
  border: solid 1px black;
}
table.myTable th
{
  border: solid 1px black;
  background-color:silver;
}
</style>"; 
 
 
 
echo "<table class = 'myTable'><tr><th> Name</th><th> Email</th></tr>";
 
?>

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
you have missed, ;

</style>"; 

Open in new window

0
 
dutaAuthor Commented:
Thank you very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now