Results 1 to 7 of 7

Thread: Encasing PHP in a <td> tag

  1. #1
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Encasing PHP in a <td> tag

    I'll explain. Have managed to get my php pages the way I want them to individually, but obviously I want to expand the pages to encompass link menus etc. so if my php code is...

    <?php
    // Make a MySQL Connection
    mysql_connect("blah...", "blah...", "blah...") or die(mysql_error());
    mysql_select_db("blah") or die(mysql_error());

    $product_sku = $_GET['product_sku'];

    // Get a specific result from the "example" table

    $result = mysql_query("SELECT * FROM shaving WHERE product_sku=$product_sku AND DEF='T05'") or die(mysql_error());

    echo "<table border='0' cellpadding='5' cellspacing='0' width='100%'>";
    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo "<tr><td bgcolor='#ffff00'><p class='BRAPRO'>";
    echo $row ['BRA']. " | ". $row['PRO'];
    echo "</p></td></tr>";
    }

    echo "</table>";

    ?>

    ... why am i getting error messages when i try to do this...

    <html>
    <head></head>
    <body>

    <table>
    <tr>
    <td>

    <?php
    // Make a MySQL Connection
    mysql_connect("blah...", "blah...", "blah...") or die(mysql_error());
    mysql_select_db("blah") or die(mysql_error());

    $product_sku = $_GET['product_sku'];

    // Get a specific result from the "example" table

    $result = mysql_query("SELECT * FROM shaving WHERE product_sku=$product_sku AND DEF='T05'") or die(mysql_error());

    echo "<table border='0' cellpadding='5' cellspacing='0' width='100%'>";
    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo "<tr><td bgcolor='#ffff00'><p class='BRAPRO'>";
    echo $row ['BRA']. " | ". $row['PRO'];
    echo "</p></td></tr>";
    }

    echo "</table>";

    ?>


    <td>
    </tr>
    </table>

    </body>
    </html>

    ... can someone show me how?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The only thing I notice is the <td> at the end of the code, which should be </td>, closing the cell that was holding all of that.

    If there error is related to mysql, your database may not match the queries, but that's impossible to know just from the code.

    What is the error you are getting?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    sorry, the <td> tag is closed at the end. i just scrawled that quickly and missed it out. it's giving me a syntax error about 'AND DEF='t05"

    note that it brings up that exact error when in fact it is coded AND DEF='T05'" correctly.

    this code works alone when in it's own php page etc., but it just fails when i try to put it into the <td> tag.

  4. #4
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    strange as it sounds, it's just worked when i have built the table around the code, but it fails when i copy and paste the php code into the existing table code.

    i don't get it. i occasionally get similar error messages always around the WHERE, ORDER BY or AND tags in requesting the info from the database.

    can you tell me is this a common thing in php?

  5. #5
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I sometimes get those errors too. I don't know the exact cause but it sometimes helps when i put single quotes around any variables in the query. In this case you could try putting single quotes around the $product_sku .
    Seems to me that mysql could use a little help in defining PRECISELY what it is to be looking for (by use of the quotes)

    on a similiar note, it is always better to use single quotes in your echo statements. I notice you have it backwards. single quotes DO NOT parse the code contained within so for regular html this works faster. What you are doing right now is unecessarily parsing tons of regular html code...

  6. #6
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm new to this forum (and to php) and still haven't seen the link to create my own thread which I think would be more appropriate ... here it goes

    Multiple Pages

    How do I call a single file to multiple pages? I want to be able to change my links from one file that I've call column_left.php (hope that's right) to a lot of different html pages. How do I do this?

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by e1seix View Post
    PHP Code:
    $product_sku $_GET['product_sku'];

    // Get a specific result from the "example" table

    $result mysql_query("SELECT * FROM shaving WHERE product_sku=$product_sku AND DEF='T05'") or die(mysql_error()); 
    I hope that you don't do exactly that: you're exposing your database to injection attacks. Call the mysql_real_escape_string function and insert the returned value into the query. I also hope you don't really send MySQL error messages to the client upon failure: that can also expose your database to attacks by revealing the mechanics of your site and database. Moreover, it looks rubbish to end users. Fail gracefully, instead.

    As for the actual problem, what does an actual query contain? That is, what is the value(s) of $product_sku in your tests? Is the resulting query actually legal?

    PHP Code:
    echo "<table border='0' cellpadding='5' cellspacing='0' width='100%'>";
    while(
    $row mysql_fetch_array$result )) {
        
    // Print out the contents of each row into a table
        
    echo "<tr><td bgcolor='#ffff00'><p class='BRAPRO'>"
        echo 
    $row ['BRA']. " | "$row['PRO'];
        echo 
    "</p></td></tr>"

    Drop out of PHP when outputting significant amounts of plain text:

    PHP Code:
    <table border="0" cellpadding="5" cellspacing="0" width="100%">
    <?php
    while ($row mysql_fetch_array($result)) {
    ?>
        <tr><td bgcolor="#ffff00"><p class="BRAPRO"><?php echo "{$row['BRA']} | {$row['PRO']}"?></p></td></tr>
    <?php
    }
    ?>
    </table>
    Preferably use CSS, rather than HTML attributes, to style documents, too.
    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •