Jump to content

Xhtml Output With Php


jadiebrown
 Share

Recommended Posts

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

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

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

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

Guest FirefoxRocks

Also, please wrap your PHP code in code tags, like this:

<?phpecho "Facebook is awesome";?>

Edited by FirefoxRocks
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...