Page 1 of 1

CSS causes Php to not work.

Posted: Sat Jan 18, 2003 5:28 pm
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.

Posted: Sat Jan 18, 2003 8:35 pm
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.

No good...

Posted: Sat Jan 18, 2003 11:49 pm
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]

Posted: Sun Jan 19, 2003 7:34 am
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

Posted: Mon Jan 20, 2003 8:09 am
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 :)