How to code <table> arguments within PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jej1216
    New Member
    • Aug 2006
    • 40

    How to code <table> arguments within PHP

    OK, I'm back again.

    On one of my PHP pages, I build a table using the following code snippet:
    [code=php]
    <?php
    echo "<table><THEAD> <tr>";
    echo "<td><b>Inciden t</b></td>";
    echo "<td><b>Facilit y</b></td>";
    echo "<td><b>Locatio n</b></td>";
    echo "<td><b>Per son</b></td>";
    echo "<td><b>Inj ury</b></td>";
    echo "<td><b>Severit y</b></td>";
    echo "<td><b>Inciden t Date</b></td></tr></THEAD>";
    while ($myrow = mysql_fetch_arr ay($result))
    {
    echo "<TBODY><tr><td >".$myrow["incident_i d"]."</td>";
    echo "<td>&nbsp ".$myrow["fac_id"]."</td>";
    echo "<td>&nbsp ".$myrow["room_descr "]."</td>";
    echo "<td>&nbsp ".$myrow["person_typ e"]."</td>";
    echo "<td>&nbsp ".$myrow["injury"]."</td>";
    echo "<td>&nbsp ".$myrow["severity"]."</td>";
    echo "<td>&nbsp ".$myrow["inc_date"]."</td>";
    }
    echo "</tr></TBODY></table>";
    ?>
    [/code]
    It works fine, but I am unable to add the other arguments to <table> such as border, class, etc.

    I worked around this on one file by jumping out of php and coding the html <table> arguments and then jumping back into php to echo the data, but there must be a better way to do this.

    Is there a way to enter the table arguments within php? I want something like
    [code=html]
    <table border name='Mytable class'='sortabl e'>
    [/code]
    Thanks,
    jej1216
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Are you trying to dynamically add these attributes at runtime, or do you need to make a one-time upgrade?

    Comment

    • jej1216
      New Member
      • Aug 2006
      • 40

      #3
      Originally posted by pbmods
      Are you trying to dynamically add these attributes at runtime, or do you need to make a one-time upgrade?
      I want to make a coding change that will be static - one time. I mainly want to add the border argument so the table has a better appearance.

      Comment

      • jej1216
        New Member
        • Aug 2006
        • 40

        #4
        I withdraw the question - it works fine. I guess I fat-fingered it before.

        Sorry.

        Comment

        • smnuman
          New Member
          • Jun 2007
          • 5

          #5
          Originally posted by jej1216
          OK, I'm back again.
          ...snip...
          I worked around this on one file by jumping out of php and coding the html <table> arguments and then jumping back into php to echo the data, but there must be a better way to do this.

          Is there a way to enter the table arguments within php? I want something like
          [code=html]
          <table border name='Mytable class'='sortabl e'>
          [/code]
          Thanks,
          jej1216
          If I understand your quest, you just do not like to break-up your output strings in the middle to accommodate your php variable data. If this is right, the the following may be helpful.
          PHP allows you to use two types of QUOTEs : the single-quotes and the double quotes.
          Generally single-quotes are non-variable accommodating while the double-quotes are variable accommodating. It means that you can put in the variables in your strings. Like this:
          [PHP]
          $var1 = 2;
          echo "There are $var1 ways to create a string in PHP";
          # This outputs : There are 2 ways to create a string in PHP
          [/PHP]
          or may be like the following if you are worried about the array presentation.
          [PHP]
          $var2 = "two";
          $var3 =array("single" => 1, "double"=>2 );
          echo "Double quote has $var2 sets of $var['double'] apostrophes."
          # OUTPUT : Double quote has two sets of 2 apostrophes.
          [/PHP]
          Hoe this gives you some idea to go further.

          Comment

          Working...