PHP Variable in HTML Table Cell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johnbrasfield
    New Member
    • Apr 2013
    • 2

    PHP Variable in HTML Table Cell

    In a PHP window that includes an HTML table, how do you put the value of the PHP variable in a table cell?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I'm not sure what your question is. There's no difference in how you echo a variable in or out of a table cell. You must have an additional complication that you have not told us about.

    Comment

    • johnbrasfield
      New Member
      • Apr 2013
      • 2

      #3
      How DO you echo a variable in or out of a table cell

      Originally posted by Rabbit
      I'm not sure what your question is. There's no difference in how you echo a variable in or out of a table cell. You must have an additional complication that you have not told us about.
      I got the value I need into a PHP variable with $uid = $_POST['uid'] and can echo the value of $uid to the window; now I want to put the value into an HTML table cell. Are you saying I should include value=<?php echo $uid ?> when defining the table cell? I do not under stand your phrase 'There's no difference in how you echo a variable in or out of a table cell' how DO you echo a variable in or out of a table cell?

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        An example when you're not doing it in a table cell:
        Code:
        <div><? echo $variable; ?></div>
        An example when you're doing it in a table cell:
        Code:
        <td><? echo $variable; ?></td>
        There's no difference. Only the surrounding element changes.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          PHP doesn't care what you are creating, whether it's a HTML link, HTML table, HTML paragraph, XML elements, JavaScript code, or even things like binary strings. It's all just a bunch of text as far as PHP is concerned. You can put a echo statement wherever you want.

          But, just to point one thing out. If you are putting PHP values originating from user input into a HTML page, be sure to run it through htmlentities first. Also, if the values are going into HTML element attributes (like the <input> value attribute), then surround them with quotes.
          Code:
          // Potentially problematic and unsafe.
          <input value=<?php echo $variable; ?>>
          
          // Less problematic, but still unsafe.
          <input value="<?php echo $variable; ?>">
          
          // Safe and not at all problematic.
          <input value="<?php echo htmlentities($variable, ENT_QUOTES, "UTF-8"); ?>">

          Comment

          Working...