How to use css style in php


Tags: php,css,echo

Problem :

Im using php to display data from mysql. Here are my css statements:

<style type=”text/css”>
table {
    margin: 8px;
}

th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: .7em;
    background: #666;
    color: #FFF;
    padding: 2px 6px;
    border-collapse: separate;
    border: 1px solid #000;
}

td {
    font-family: Arial, Helvetica, sans-serif;
    font-size: .7em;
    border: 1px solid #DDD;
}
</style>

They are used for displaying table, tableheader, tabledate. Im new to php css, so im just wondering how to use the above css style in php displaying codes:

<?php>
echo "<table>";
echo "<tr><th>ID</th><th>hashtag</th></tr>";
while($row = mysql_fetch_row($result))
{
    echo "<tr onmouseover=\"hilite(this)\" onmouseout=\"lowlite(this)\"><td>$row[0]</td>                <td>$row[1]</td></tr>\n";
}
echo "</table>";
<?>


Solution :

Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation semantics (the look and formatting) of a document written in a markup language. more info : http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS is not a programming language, and does not have the tools that come with a server side language like PHP. However, we can use Server-side languages to generate style sheets.

<html>
<head>
<title>...</title>
<style type=”text/css”>
table {
margin: 8px;
}

th {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
background: #666;
color: #FFF;
padding: 2px 6px;
border-collapse: separate;
border: 1px solid #000;
}

td {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
border: 1px solid #DDD;
}
</style>
</head>
<body>
<?php>
echo "<table>";
echo "<tr><th>ID</th><th>hashtag</th></tr>";
while($row = mysql_fetch_row($result))
{
echo "<tr onmouseover=\"hilite(this)\" onmouseout=\"lowlite(this)\"><td>$row[0]</td>                <td>$row[1]</td></tr>\n";
}
echo "</table>";
?>
</body>
</html>

    CSS Howto..

    How to hide all element on html page except one div using css?

    How do I combine this 2 sets of coding together to form a mega drop down nav

    How to Change Css coding with a link [closed]

    How to add 10 pixels to a dynamic top position in CSS using SASS

    How to get WordPress Twenty Ten theme sub-menus to expand to their contents (CSS)?

    How to target the href to div

    How to do like this list using
  • and CSS?
  • How to apply CSS to list in HTML

    How to change the attribute value of an element with by another element Selector in HTML + CSS?

    How do I select every other div class element using just CSS (no js)

    How to highlight the menu item for the sort type of data on the page?

    How to make an empty div or container glow with pure CSS?

    How can i set png icon collection with CSS?

    How can I set the CSS class of an element in a Rails view?

    How to add two class styles to anchor tag

    How to use dp to calculate shadows - web development HTML CSS

    How to implement vertical tables using html5/CSS

    How do I access font features in CSS?

    How to include a custom CSS file in TYPO3

    How to remove a CSS style on the fly

    How to add an existing class to td in css file?

    Show bootstrap glyphicon in link when hovering

    How to prevent inherit for H1?

    How to make a CSS composite scalable

    How to break this Javascript into seperate CSS classes?

    How do I correct overlapping spacing error in CSS when it wraps text?

    How to set the background image width using CSS?

    How to change the css of a div using the click function on jQuery, but however twice instead of once?

    CSS - How to view computed font size?

    How to put bootstrap glow (used in the 'form-control' CSS class) on a div?