print tables by php code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 848lu
    New Member
    • Dec 2006
    • 37

    print tables by php code

    hi, i am trying to get my code to print HTML tables and other html tags but i get error right from the begining when i print a table, where within it there are more tables and then i print my results from queries.


    heres the code where it starts from
    [PHP]print "<table cellpadding="0" cellspacing="0" border="0" align="center" >"[/PHP]

    for some reasons it dont let me, any comments?
  • shane3341436
    New Member
    • Mar 2007
    • 63

    #2
    Originally posted by 848lu
    hi, i am trying to get my code to print HTML tables and other html tags but i get error right from the begining when i print a table, where within it there are more tables and then i print my results from queries.


    heres the code where it starts from
    [PHP]print "<table cellpadding="0" cellspacing="0" border="0" align="center" >"[/PHP]

    for some reasons it dont let me, any comments?
    If that is not the type mistake, you cannot use double quote like that
    because print command displays the content enclosed within either the pair of double quotes or a pair of single quotes.
    You should use
    [PHP]print '<table cellpadding="0" cellspacing="0" border="0" align="center" >';[/PHP]

    Comment

    • 848lu
      New Member
      • Dec 2006
      • 37

      #3
      Originally posted by shane3341436
      If that is not the type mistake, you cannot use double quote like that
      because print command displays the content enclosed within either the pair of double quotes or a pair of single quotes.
      You should use
      [PHP]print '<table cellpadding="0" cellspacing="0" border="0" align="center" >';[/PHP]

      thanks...it works, i also tried it like this
      [PHP]print "<table cellpadding='0' cellspacing='0' border='0' align='center' >";[/PHP]

      whats the differene between them?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Think of quotes as brackets..

        eg this is the beggining bracket ( this is the closing bracket )
        this is the opening quote " this is the closing quote "

        PHP can't tell which quote is closing what so it goes for the first two.

        i.e
        [php]
        $string = "String opened... string closed";
        $string = "String opened... quote within string " string closed"; ("
        /*the quote within the string will be seen as the closing quote for the opening one.*/
        /*however, if we were to use different types of quotes...*/
        $string = "string opened... 'quote within string ' string closed";
        //the single quote would not close the initial quote
        //you can escape quotes with a backslash \
        $string "string opened... quote within string \" string closed";
        //the quote was escaped and therefore doesnt closer the initial quote
        [/php]

        Comment

        • spudse
          New Member
          • Jan 2008
          • 11

          #5
          [code=php]
          echo $var; // Results in the value of $var being printed
          echo '$var'; // Results in the word '$var'
          echo "$var"; // Results in the value of $var being printed
          [/code]
          Source

          With doubles quotes (") you can print things like:
          [code=php]
          $name = 'spudse';
          echo "My name is $name";
          [/code]

          With single quotes you need to do this like this:
          [code=php]
          $name = 'spudse';
          echo 'My name is ' . $name;
          [/code]

          Also, some special characters, like newlines \n are printed as newline when encapsulated by double quotes and as characters when encapsulated by single quotes.

          Comment

          Working...