aligning tables with printf, need help

Discussion in 'PHP' started by mezner, Jun 21, 2010.

  1. #1
    I have data that is being outputted with printf:

    printf("<tr><td>%s</td> <td>%s</td> <td>\$%s</td> </tr>", $sku, $name, $price);
    PHP:
    As you can see, there are 3 variables that are being put into 3 columns, each query gets its own table row.

    The problem I'm having is being able to do <td align="center">. It brings up an error saying:

    Parse error: syntax error, unexpected T_STRING

    I was wondering how I'm allowed to use the = and " symbols to get my columns aligned!
     
    mezner, Jun 21, 2010 IP
  2. bogdanas

    bogdanas Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well there are several solutions, I think the best is not to use printf, use echo.
    echo "<tr><td align=\"center\">$sku</td> <td>$name</td> <td>$price</td> </tr>";
    if printf:
    printf("<tr><td align='center'>%s</td> <td>%s</td> <td>\$%s</td> </tr>", $sku, $name, $price);
    Or:
    printf("<tr><td align=\"center\">%s</td> <td>%s</td> <td>\$%s</td> </tr>", $sku, $name, $price);
     
    bogdanas, Jun 21, 2010 IP
  3. mezner

    mezner Peon

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ah thank you! I always have trouble remembering how to use the \ before quotes.
     
    mezner, Jun 21, 2010 IP