CSS causes Php to not work.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

CSS causes Php to not work.

Post by eggoz »

I am rather new to php and adding code php code to html. I wrote a php, which worked with no problem. After I added some html along with some css styles, it hasn't worked. Will styles interfere with this in anyway? I have looked over my code more than enough times and it looks a ok to me. I have narrowed it down to this small section. Did I do this wrong?

Code: Select all

<table style="border"> 
<tr> 
<td> 
<?php 
print "<table style="products">\n"; 
while ( $a_row = mysql_fetch_row( $record ) ) &#123; 
   print "<tr>\n"; 
   foreach ( $a_row as $field ) 
      print "\t<td style="padding">$field</td>\n"; 
   print "</tr>\n"; 
&#125; 
print "</table>\n"; 
mysql_close( $link ); 
?> 
</td> 
</tr> 
</table>
The only thing that is different is from my first script is the table that surrounds everything and the styles. Thanks for your help.
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

Your problem is trying to print out a double quote around the style names. Since you're using double quotes to contain the argument for the print command, you need to put a backslash in front of any double quote you actually want to output:

Code: Select all

<?php  
print "<table style="products">\n";  
while ( $a_row = mysql_fetch_row( $record ) ) {  
   print "<tr>\n";  
   foreach ( $a_row as $field )  
      print "\t<td style="padding">$field</td>\n";  
   print "</tr>\n";  
}  
print "</table>\n";  
mysql_close( $link );  
?>
See the section of the PHP manual on string data types for more info.
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

No good...

Post by eggoz »

Yeah, I saw that in another forum and tried it, but I still get the same problem. Here is the page... http://www.aardvarksafety.com/first/pro ... ue=AERO004. And here is my code... http://www.aardvarksafety.com/first/pro ... ts_css.txt. As you can see, I have done excatly what I have read. Any other ideas? Thanks. [/url]
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

When you are trying to apply a CSS class to an element, as you are, you should be using the class attribute instead of the style attribute. Try:

Code: Select all

<?php
print "<table class="products">\n"; 
while ($a_row = mysql_fetch_row($record)) { 
	print "<tr>\n"; 
	foreach ($a_row as $field) { 
		print "\t<td class="padding">$field</td>\n"; 
	}
	print "</tr>\n"; 
} 
print "</table>\n";
mysql_close($link);
?>
So instead of style="products" and style="padding" you have class="products" and class="padding".

Mac
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

Good catch, Mac! I hadn't noticed that. That's why you're the Admin and I'm just a Developer :)
Post Reply