jadiebrown Posted April 18, 2009 Share Posted April 18, 2009 I am using Aptana for an exercise coming directly from a php study guide. The idea is to create a very basic table to understand more about creating XHTML output in the PHP language. I am using the output method. I have also tried the same exercise using Heredocs but still have the same problem.Problem: When viewed in a browser the table is only one cell. There should be four cells (two rows, two columns). But all the text is just evenly spaced in one cell - no table as such.Here is the code I have used which comes directly from the guidebook I am using for study:<?php$name = "John";$address = "123 Main Str.";$output = " ";$output .= "<table style= \"border: 1px solid black\ "> \n";$output .= " <tr> \n";$output .= " <td>Name</td> \n";$output .= " <td>$name</td> \n";$output .= " </tr> \n";$output .= " <tr> \n";$output .= " <td>Address</td> \n";$output .= " <td>$address</td> \n";$output .= " </tr>$output .= "</table>print $outputPS if anybody knows what the third line of the code (output = " " is for, that would be great! Link to comment Share on other sites More sharing options...
jadiebrown Posted April 18, 2009 Author Share Posted April 18, 2009 Apologies my coding was a little messy; here is the correct code I used:<?php$name = "John";$address = "123 Main Str.";$output = " ";$output .= "<table style= \"border: 1px solid black\ "> \n;$output .= " <tr> \n";$output .= " <td>Name</td> \n";$output .= " <td>$name</td> \n";$output .= " </tr> \n";$output .= " <tr> \n";$output .= " <td>Address</td> \n";$output .= " <td>$address</td> \n";$output .= " </tr> \n";$output .= "</table>\n";print $output?> Link to comment Share on other sites More sharing options...
jeffman Posted April 18, 2009 Share Posted April 18, 2009 Are you just typing this code here or pasting it? This line looks broken both times you've shown it to us, but it's different both times, so I don't know what's going on for sure:$output .= "<table style= \"border: 1px solid black\ "> \n;The space between the final escape character and quotation mark is incorrect. And you do need a quote mark after the newline character.But I don't want to mess with this too much unless you're pasting the actual code, because little details make huge differences.$output = " ";This line just initializes $output so all the following lines can use the .= operator. You could lose this line if you took the dot out of the following line. Link to comment Share on other sites More sharing options...
jadiebrown Posted April 18, 2009 Author Share Posted April 18, 2009 I have figured out the reason:I needed to code the table tag like this in order to actually see the cells. Effectively I had created a border value of "0".<table border="1"> Link to comment Share on other sites More sharing options...
jeffman Posted April 18, 2009 Share Posted April 18, 2009 Yes. If you are going to use CSS to style a table, then the <td> elements need definitions also. Ideally, that would happen in a style sheet, not in the tags.The border property in the <table> tag is still legal, but you can have more control if you use CSS.But that's your decision. Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted April 19, 2009 Share Posted April 19, 2009 Also, please wrap your PHP code in code tags, like this: <?phpecho "Facebook is awesome";?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.