XHTML Output with PHP

Discussion in 'Programming' started by jadiebrown, Apr 18, 2009.

to remove all ads.
  1. jadiebrown

    jadiebrown New Member

    Messages:
    24
    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 $output

    PS if anybody knows what the third line of the code (output = " ";) is for, that would be great!
     
  2. jadiebrown

    jadiebrown New Member

    Messages:
    24
    Apologies, my coding was a little messy; here is the correct coding 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
    ?>
     
  3. jadiebrown

    jadiebrown New Member

    Messages:
    24
    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">
     

Share This Page