Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

html php and CSS 1

Status
Not open for further replies.

TheSponge

Technical User
Jul 2, 2003
442
GB
Im sure this is a simple one, but Im unsure,

I have a stylesheet called "sheet1.css"

and I have installed a referrers.php script, but it isnt formatting properly?

what is the PHP code to link to a .css style sheet please?



A+,CCNA
 
$saved.="<td><a href=\"go.php?$d->id\" title=\"in/out - $d->hitsin/$d->hitsout\" target=\"$d->id\">$url</a></td>";

if I change the above line to <td class=""> it doesnt work?

Thannks

A+,CCNA
 
1. What does not work?
2. What is the declaration of that class in css?
3. Here's a simplified example. Does this work?
Code:
$saved  = "<style type='text/css'>\n";
$saved .= " .title { background: red; }\n";
$saved .= "</style>\n";
$saved .= "<table><tr><td class='title'><a href='go.php?$d->id' title='in/out - $d->hitsin/$d->hitsout' target='$d->id'>$url</a></td></tr></table>";
Without providing more information we can't help you much better. The main things we should know are:

1. What is the error/problem you're getting.
2. What is the class name and its declaration.
 
Curious, but what does "referrers.php" have to do with your stylesheet? Is your page that's not working called "referrers.php"?

If you're properly escaping the "" in <td class=""> (<td class=\"\"> then you're not bringing in your stylesheet properly.

It's also possible that you haven't defined your css class properly in your stylesheet.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Just a test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="sheet1.css" rel="stylesheet" type="text/css" media="screen">
</head>
<body>
<?php

$saved = "";
$saved .= "<table><tr>";
$saved .= "<td class=\"classname\"><a href=\"go.php?$d->id\" title=\"in/out - $d->hitsin/$d->hitsout\" target=\"$d->id\">$url</a></td>";
$saved .= "</tr></table>";
?>
</body>
</html>

[cheers]
Cheers!
Laura
 
Many Many Thanks guys...

in my referrers.php

I had:

$saved.="<td class="cellcontent"><a href=\"go.php?$d->id\" title=\"in/out - $d->hitsin/$d->hitsout\" target=\"$d->

it now works with this:

$saved.="<td class='cellcontent'><a href=\"go.php?$d->id\" title=\"in/out - $d->hitsin/$d->hitsout\" target=\"$d->

I used the single quote marks...

How very odd?

Many thanks again, perhaps someone could explain why that happened...

A+,CCNA
 
That's PHP syntax = use either single quote marks, or escape your double-quotes, as explained to you when you posted this problem a few days ago.

[cheers]
Cheers!
Laura
 
Not odd at all. As Laura explained, your problem was strictly delimiting strings in php. What php saw of your code was a string ("<td class=") followed by a php command (cellcontent) and followed by another string (everything else). PHP choked because it had no idea what kind of command cellcontent was. Do you know why you have backslashes in front of all your other double quotes? It is because putting a backslash in front will mean that the quote does not delimit string but is the actual output of the double quote. And that's all there is to it. My solutions used double quotes to delimit string in php and single quotes to delimit attribute values in html and so no escaping (putting backslash in front of it) was needed. Code is easier to read that way.
 
Vragabond said:
My solutions used double quotes to delimit string in php and single quotes to delimit attribute values in html and so no escaping (putting backslash in front of it) was needed. Code is easier to read that way.

That is an excellent idea - thank you for the tip!

[cheers]
Cheers!
Laura
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top