SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Table Problem

  1. #1
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Table Problem

    I have created a table but I cannot position it right. It positions itself at least half way down the page.

    Why is this??

  2. #2
    SitePoint Wizard bronze trophy conradical's Avatar
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    2,355
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Is it the first object on your page? Are you sure there is no other code above your table? Set your TOP MARGIN to 0.

    There really isn't any other reason for it to slide down. Post some code.

    If all fails and you are yet unable to get your table up, try some Viagra

  3. #3
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All that is above it is php code - error checking, database connection etc. Any ideas??

    Here is the code:

    PHP Code:
    echo '<table width="600" border="1" cellspacing="2" cellpadding="0">';
    for (
    $i=0$i<$num_results$i++)
    {
       
    $row mysql_fetch_array($result);
       echo 
    '<tr><td>Client:</td><td>'.$row['client'].'</td></tr><br />';
      echo 
    '<tr><td>Address: </td><td>'.$row['address'].'<br />'.$row['address2']
      .
    $row['address3'].'<br />'.$row['address4'].'<br />'.$row['city'].
      
    '<br />'.$row['state'].'<br />'.$row['zip'].'<br />'.$row['country'].'</td></tr><br />';   
    }
    echo 
    '</table>'

  4. #4
    SitePoint Wizard bronze trophy conradical's Avatar
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    2,355
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Hello,
    The error check/db connection can be above the <head> tag of your page.

    Try that and see if it still drops the table.

    I don't know if the dynamic table could be a cause...but i guess we could check that if after you trouble shoot other areas first.

  5. #5
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're not supposed to have <br />s after </tr>s..

  6. #6
    SitePoint Wizard bronze trophy conradical's Avatar
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    2,355
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Sorccu
    You're not supposed to have <br />s after </tr>s..
    Yes. I somehow missed that!

  7. #7
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope. Didn't work.

  8. #8
    SitePoint Wizard bronze trophy conradical's Avatar
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    2,355
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Ok, try this.

    Remove the dynamic table and add a regular table to test it. If it does not drop down, then it is the dynamic table. If that drops too, then there is someother issue. Post the entire page code...and not a section.

  9. #9
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the code:

    Code:
    <?php
    include('db_fns.php');
    // Declare Variable
    $client = $_POST["client"];
    $entity = $_POST["entity"];
    $director = $_POST["director"];
    $manager = $_POST["accounting_manager"];
    // Connect to Database
    $conn = db_connect();
    if (!$conn)
      return 'Could not connect to Database;';
     
    // Perform Query
    $query = "select * from client_universe where client='$client' and entity='$entity' and director='$director' and accounting_manager='$manager'";
    $result = mysql_query($query) or die(mysql_error());
    $num_results = mysql_num_rows($result);
    echo '<table width="600" border="1" cellspacing="2" cellpadding="0">';
    for ($i=0; $i<$num_results; $i++)
    {
       $row = mysql_fetch_array($result);
       echo '<tr><td>Client:</td><td>'.$row['client'].'</td></tr><br />';
      echo '<tr><td>Entity: </td><td>'.$row['entity'].'</td></tr><br />';   
    }
    echo '</table>';
    ?>

  10. #10
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Ireland
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take out all those BR's for starters. They are not used: TR stands for Table Row, so each new <tr> will make a new row, eliminating the need for line-breaks. Observe the changes I make (both in PHP code and HTML):

    PHP Code:
    <?php
    include('db_fns.php');
    // Declare Variable
    $client $_POST["client"];
    $entity $_POST["entity"];
    $director $_POST["director"];
    $manager $_POST["accounting_manager"];
    // Add slashes if we need to, preventing SQL Injection
    if (!get_magic_quotes_gpc()) {
        
    $client   addslashes($client);
        
    $entity   addslashes($entity);
        
    $director addslashes($director);
        
    $manager  addslashes($manager);
    // Connect to Database
    $conn db_connect();
    if (!
    $conn)
      return 
    'Could not connect to Database;';

    // Perform Query
    $query "SELECT * FROM client_universe WHERE client='$client' AND entity='$entity' AND director='$director' AND accounting_manager='$manager'";
    $result mysql_query($query) or die(mysql_error());
    echo 
    '<table width="600" border="1" cellspacing="2" cellpadding="0">';
    while (
    $row mysql_fetch_array($result)) {
        echo 
    '<tr><td>Client:</td><td>'.$row['client'].'</td></tr>';
        echo 
    '<tr><td>Entity: </td><td>'.$row['entity'].'</td></tr>';
    }
    echo 
    '</table>';
    ?>
    While it still isn't great code, it should work better than before. Give it a try, and tell us if you are still getting a problem.

    Good Luck


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
  •