?
Solved

How to embed CSS in PHP?

Posted on 2009-04-18
6
Medium Priority
?
622 Views
Last Modified: 2012-08-13
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
Comment
Question by:duta
  • 3
  • 2
6 Comments
 
LVL 6

Assisted Solution

by:JoachimMartinsen
JoachimMartinsen earned 600 total points
ID: 24174918
You need to echo out the CSS code.
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24175018
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
 

Author Comment

by:duta
ID: 24175022
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 1400 total points
ID: 24175032
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24175033
you have missed, ;

</style>"; 

Open in new window

0
 

Author Closing Comment

by:duta
ID: 31571768
Thank you very much!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question