Jump to content

PHP and 'print' (div layers) [RESOLVED]


irken

Recommended Posts

Hi.

I can't seem to figure out why this piece of code won't produce boxes of layers ligned up correctly. It's just ignoring the top and left values of the <div style="..">.

[code]
<?php

    include($_SERVER['DOCUMENT_ROOT'] . '/pixels/includes/header.htm');
   
    session_start();
    if (!$_SESSION['username'])
    {
        echo 'Login first.';
        exit;
    }
       
    $ping = "pong";
    include($_SERVER['DOCUMENT_ROOT'] . '/pixels/includes/database.mysql.php');
   
    $username = $_SESSION['username'];
    $password = $_SESSION['password'];
    $hostname = $_SESSION['hostname'];
       
    $connection = new mysql("localhost", "root", "", "pixels");
    $connection->connect();
   
    // Set up the query string.
    $query =
        "
            SELECT * FROM `users` WHERE username='$username'
        ";
       
    $result = $connection->query($query);
   
    // We found a match.
    if (mysql_num_rows($result) > 0)
    {           
        echo 'Welcome ' . $_SESSION['username'] . ".<br /><br />\n";
       
        $x = 0;
        $y = 0;
       
        for ($i = 1; $i <= 45; $i++)
        {
            $field = '<a href="field.php">Field' . $i . 'X = ' . $x . '</a>';
           
            $newX = ($x + 10);
           
            print "<div style=\"position:absolute; width: 60px; height: 60px; top: $y px; left: $newX px; border-style: solid\">$field</div>";
           
            if ($i == 8 || $i == 23 || $i == 38)
            {
                $y += 55;
                $x =- 30;
            }
           
            if ($i == 15 || $i == 30)
            {
                $y += 55;
                $x =- 60;
            }
           
            $x += 60;
        }
    }
    else
    {
        echo 'Weird.. user not found, but was in session.';
        session_destroy();
        exit;
    }
   
    include($_SERVER['DOCUMENT_ROOT'] . '/pixels/includes/footer.htm');
?>
[/code]

The above don't work. Now I have tested the following piece of code in a .htm file.

[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
</head>
<body>
    <div style="position:absolute; width: 60px; height: 60px; top: 55px; left: 100px; border-style: solid">Test</div>
    <div style="position:absolute;width: 60px; height: 60px; top: 0px; left: 10px; border-style: solid">Test</div>
    <div style="position:absolute; width: 60px; height: 60px; top: 110px; left: 250px; border-style: solid">Test</div>
</body>
</html>
[/code]

Which aligns them acording to the set top and left. As far as I can see, the PHP code outputs the exact same thing, so I'm puzzled.

Thanks for the help.
Link to comment
https://forums.phpfreaks.com/topic/30639-php-and-print-div-layers-resolved/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.