JavaScript and client side scripting.
Moderator: General Moderators
eggoz
Forum Commoner
Posts: 43 Joined: Fri Dec 27, 2002 8:51 pm
Post
by eggoz » Sat Jan 18, 2003 5:28 pm
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 ) ) {
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 );
?>
</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 » Sat Jan 18, 2003 8:35 pm
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.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Sun Jan 19, 2003 7:34 am
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 » Mon Jan 20, 2003 8:09 am
Good catch, Mac! I hadn't noticed that. That's why you're the Admin and I'm just a Developer