SitePoint Sponsor

User Tag List

Results 1 to 17 of 17

Thread: Aligning returned MySQL data

  1. #1
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Aligning returned MySQL data

    Hi.
    I have a score card being returned with all scores returned from a MySQL database.

    The scorecard is in simple HTML <table> format.

    However on returning the scores they wont align properly. Aligning 'left' is fine and goes straight up against the edge of the cell. However aligning 'right' will not display really as it should. Just leaves a space before the edge so does not align right at the edge of the cell.

    Little Diagram to explain:

    want it like this:
    Code:
    -------------
    |         21|
    -------------
    but this happens
    Code:
    -------------
    |        21 |
    -------------
    Any one had this problem or know why ? I for design purposes need to make sure it's at the edge like normal html aligned right would be. Is it to do with the PHP? MySQL database? im lost.......

  2. #2
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to clip the white spaces off, Sorry can't remember the function... but its a comman string function and will be in the php manual


    "Will I ever find my way to GURU?"

  3. #3
    SitePoint Zealot scriptfactory's Avatar
    Join Date
    Oct 2003
    Location
    Kaiserslautern, Germany
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I doubt trim() would make a difference since whitespaces mean just about nothing in HTML. Unless his whitespaces were &nbsp; it wouldn't cause that. The space before the edge of the cell is probably due to the table cell's padding.

    Add something like style="padding-right: 0px;" to the table cell and see if that fixes the problem.

    If that doesn't work then just try trim(). Hey, who knows. It might work.

  4. #4
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Will try these later today - cheers !
    weird one is this but very annoying

  5. #5
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The style did nothing.
    please see here the problem:

    scorecard

    the bramley columns of data should be aligning right to the cell. Notice that the table moust be OK as the title of the columns do this fine. Now looking for the witespace function, can any one advise ? Looked and yet to find.

  6. #6
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tried:
    PHP Code:
    $trimmed_frame_1_f trim($row["frame_1_f"]);
    $trimmed_frame_1_f trim($row["frame_1_o"]);
    $trimmed_frame_2_f trim($row["frame_2_f"]);    
    $trimmed_frame_2_o trim($row["frame_2_o"]); 
    then used the variables to display. Still the gap is there but the "blabka_0"dont appear. This the correct way to use trim ?

    also trie:
    PHP Code:
    $frame_1_f $row["frame_1_f"];
    $frame_1_o $row["frame_1_o"];
    $frame_2_f $row["frame_2_f"];
    $frame_2_o $row["frame_2_o"];
    $trimmed_frame_1_f trim($frame_1_f);
    $trimmed_frame_1_o trim($frame_1_o);
    $trimmed_frame_2_f trim($frame_2_f);
    $trimmed_frame_2_o trim($frame_2_o); 
    Still dont align properly again see link "scorecard above"

  7. #7
    SitePoint Zealot oivaf's Avatar
    Join Date
    Apr 2003
    Location
    Mexico
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I really believe that this thread should belong to this forum

    well for starters the columns look right in Opera 7.21 and Firefox 0.8 but in IE 6 I clearly see the extra space

    Experimenting I found that to eliminate that obnoxious space one method could be removing the width attribute from the TD tag corresponding to the affected row. That is if you previously had this
    HTML Code:
    </tr><tr>
       <td width='100'><div  align='right'><strong>James</strong></div></td>
      <td width='50'><div style='padding-right: 0px;'  align='right'>50</div></td>
      <td><div align='center'>-</div></td>
      <td width='50'><div align='left'>0</div></td>
      <td width='50'><div style='padding-right: 0px;' align='right'>50</div></td>
      <td><div align='center'>-</div></td>
      <td width='50'><div align='left'>0</div></td>
      <td width='30'>&nbsp;</td>
      <td><div align='center'>12 </div></td>
    </tr><tr>
    you would change it to
    HTML Code:
    </tr><tr>
       <td width='100'><div  align='right'><strong>James</strong></div></td>
      <td><div style='padding-right: 0px;'  align='right'>50</div></td>
      <td><div align='center'>-</div></td>
      <td width='50'><div align='left'>0</div></td>
      <td><div style='padding-right: 0px;' align='right'>50</div></td>
      <td><div align='center'>-</div></td>
      <td width='50'><div align='left'>0</div></td>
      <td width='30'>&nbsp;</td>
      <td><div align='center'>12 </div></td>
    </tr><tr>
    HTH

  8. #8
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How strange, the WIDTH was causing the problem. Not too sure i understand why at all. You have any ideas why this is? ?

    Reason I put in here is since its PHP im using and dynamic data which is the problem displaying thought I would get more people replying in here who may have had the same past problems. Although it seems it is a HTML problem now it still only applies to the data being queried from the MySQL database.

    Many thanks for the above, looks fine now. Just does this mean never can i use width tags for dynamic data cells? Any body who displays dynamic data from MySQL databases care to comment on whether they have this problem too and what they do to overcome it?

  9. #9
    SitePoint Zealot oivaf's Avatar
    Join Date
    Apr 2003
    Location
    Mexico
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tjsaynor
    You have any ideas why this is?
    maybe cause IE is a crappy browser (just my opinion)

    Quote Originally Posted by tjsaynor
    Just does this mean never can i use width tags for dynamic data cells?
    I really don't think so Maybe it's a hidden bug in the markup.

    Also I can see that you're not using a doctype, nor html, head, and body tags that could be a probable cause but I dunno Why don't you try to use the W3C validator ?

  10. #10
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would I not be there all day trying to validate this code ?
    All HTML is echo'd from PHP.

    I have an :
    index.php
    config.php
    header.php

    and then in includes folder
    class.scorecard.php


    In index PHP before and after the <?php tages open and close should i put the html body and declaration in there? How i know which declaration to use ? as u prob can see novice really
    class.tables.php

  11. #11
    SitePoint Zealot oivaf's Avatar
    Join Date
    Apr 2003
    Location
    Mexico
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tjsaynor
    Would I not be there all day trying to validate this code ?
    All HTML is echo'd from PHP.
    of course .....though you could validate the resulting output (by using the View Source in your browser) ?

    Quote Originally Posted by tjsaynor
    In index PHP before and after the <?php tages open and close should i put the html body and declaration in there?...
    this could be a common HTML header
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <title>Your Page title</title>
    </head>
    <body>
    and this the HTML footer
    HTML Code:
    </body>
    </html>
    The idea is to place all yout html output between the html header and footer. Obviously this depends on how your PHP files are setup

    HTH

  12. #12
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your a true star oivaf.

    All your help has been very much appreciated.
    Many Thanks TJ

  13. #13
    SitePoint Zealot oivaf's Avatar
    Join Date
    Apr 2003
    Location
    Mexico
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey thanks , just giving back to this great community

  14. #14
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another PROBLEM / QUERY.
    may as well post in this thread to save multiple posts.

    I have a login system that works fine, works both on server and testing server on my machine. However on testing server only i get some notices not errors but emphasising again its working fine still.

    These notices are:
    Notice: Undefined index: LOGIN in c:\inetpub\wwwroot\Bramley_libs\includes\class.scorecard.php on line 123
    and:
    Notice: Undefined index: password in c:\inetpub\wwwroot\Bramley_libs\includes\class.scorecard.php on line 192
    I know basically what it means. It's saying when the script executes these lines of code are testing for variable (things) that are yet to exist.
    line 123
    PHP Code:
    if($_SESSION["LOGIN"] == 1){ 
    line 192
    PHP Code:
    if($_POST["password"] == $password){ 
    Again there is no problems with the working and online these notices dont come up. However they do locally and in a way they do make sense. Just wondered what i should do? leave it, do something to make the parser happy? .......

  15. #15
    SitePoint Zealot oivaf's Avatar
    Join Date
    Apr 2003
    Location
    Mexico
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    interesting question.......I would probably get rid of the notices since I'm always coding with error_reporting(E_ALL) so they're pretty bothering but yes it is true that in most hosting environments the error reporting doesn't reach notices like in this case....

    A notice error has the potential to be the origin of other errors specially when you change a part of your program that uses in some way that particular variable causing the error. Also if you have register_globals ON an uninitialized variable (a common cause of Notice errors) can be set by malicious attackers outside your program

    In this specific example you've posted is just a matter of choice/taste although the consequences will depend on how your program is setup .......of course I would recommend getting rid of the notices

  16. #16
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeh I would love to get rid of the notcies just for annoyance purposes. but dont really know how to. The IF strcutures you see above are what test to see the values but neither exist untill the form is submitted because after that they then dissapear.

  17. #17
    SitePoint Zealot oivaf's Avatar
    Join Date
    Apr 2003
    Location
    Mexico
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can use the traditional isset which is precisely used to check if a variable exists

    for example to check the $_SESSION
    PHP Code:
    // this means if $_SESSION['LOGIN'] exists AND is equal to 1 
    if(isset($_SESSION['LOGIN']) && $_SESSION["LOGIN"] == 1){
        
    // do something 

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
  •