Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: Display data from database in a table with different colours

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

    Default

    Those dots aren't helping.

    $name= $row['alias'];
    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

  2. #12
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok thank you so much guys for your help. Just one more thing though.

    The output of the name works. But there is a space between the first and second letter!!! I can't find where in the script to correct that?!?!?

  3. #13
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's just because there's whitespace between the two <span> tags. Remove it, and all will be fine.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #14
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    lol thank you, silly me!!!

  5. #15
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok, the script is complete and it leads me onto another question. Lets say I have 10 names I want outputting into a table. I have just been trying by myself by the way!! But I am failing!!

    Any ideas would be a help.

    Thanks.

  6. #16
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    How are they stored?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #17
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool Display data from database in a table with different colours

    Ive created a new thread which sort of runs off the previous one because I thought it is in a way a different question to the last one even though the two are related so I hope that this is ok.

    Basically, I have this code that retrieves data from a table in a database.

    Code:
    <?php
    $dbhost = 'localhost';
    $dbuser = 'dbuser';
    $dbpass = 'dbpass';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    
    $dbname = 'dbname';
    mysql_select_db($dbname);
    
    $query = "SELECT alias FROM challengeus";
    $result = mysql_query($query) 
    or die(mysql_error()); 
    print " 
    <center>
    <table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#808080\" width=\"20%\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\"><tr> 
    <td align=center bgcolor=\"#ffffcc\"><b>Player:</b></td>
    </tr>"; 
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    { 
    print "<tr>"; 
    print "<td align=center>" . $row['alias'] . "</td>"; 
    print "</tr>"; 
    } 
    print "</table>"; 
    print "</center>";
    ?>
    and I have this code that outputs data from the database onto a webpage but into 2 different colours....eg.

    Smithster

    Code:
      <style type="text/css">
        .name-firstletter {
          color: red;
        }
        .name-rest {
          color: #48d1cc;
        }
      </style>
    </head>
    <body>
      <p>
        <span class="name-firstletter">
          <?php echo($name[0]); ?>
        </span>
        <span class="name-rest">
          <?php echo(substr($name, 1)); ?>
        </span>
      </p>
    when I put the 2 scripts together, I end up with this....

    Code:
    <html>
      <style type="text/css">
        .name-firstletter {
          color: red;
        }
        .name-rest {
          color: #48d1cc;
        }
      </style>
    <?php
    $dbhost = 'localhost';
    $dbuser = 'dbuser';
    $dbpass = 'dbpass';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    
    $dbname = 'dbname';
    mysql_select_db($dbname);
    
    $query = "SELECT alias FROM challengeus";
    $result = mysql_query($query) 
    or die(mysql_error()); 
    print " 
    <center>
    <table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#808080\" width=\"20%\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\"><tr> 
    <td align=center bgcolor=\"#ffffcc\"><b>Player:</b></td>
    </tr>"; 
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    { 
    print "<tr>"; 
    print "<td align=center>"<span class=\"name-firstletter\"><?php echo($row[0]); ?> </span> <span class=\"name-rest\"> <?php echo(substr($row, 1)); ?> </span>"</td>"; 
    print "</tr>"; 
    } 
    print "</table>"; 
    print "</center>";
    ?>

  8. #18
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    New thread created as this is really a different question. I hope the question I have asked answers this question!!

    http://www.dynamicdrive.com/forums/s...4765#post94765


    MODERATOR EDIT: This is the same discussion, so please only use one thread. It has already been discussed, so anyone who helps you may wish to review this thread when doing so. I merged the two threads. Please keep it this way, for this, and for future questions.
    Last edited by djr33; 05-30-2007 at 10:03 PM.

  9. #19
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The code (once put together) should look like so:

    Code:
    <html>
      <style type="text/css">
        .name-firstletter {
          color: red;
        }
        .name-rest {
          color: #48d1cc;
        }
      </style>
    <?php
    $dbhost = 'localhost';
    $dbuser = 'dbuser';
    $dbpass = 'dbpass';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    
    $dbname = 'dbname';
    mysql_select_db($dbname);
    
    $query = "SELECT alias FROM challengeus";
    $result = mysql_query($query) 
    or die(mysql_error()); 
    ?> 
    <center>
    <table border="5" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="20&#37;" id="AutoNumber2" bgcolor="#C0C0C0"><tr> 
    <td align=center bgcolor="#ffffcc"><b>Player:</b></td>
    </tr>
    
    <?php 
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    { 
    ?>
    <tr>
     <td align=center><span class="name-firstletter"><?php echo $row[0];?></span> <span class="name-rest"><?php echo substr($row, 1));?></span></td>
    </tr>
    <?php
    } 
    ?>
    </table>
    </center>
    Notice how I broke out of PHP parsing mode to basically make it easier to keep track of. Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  10. #20
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Well the script caused an error when first ran. So I put the exact HTML for the span section into it and this time there was no error. But only the top part of the table is shown. Nothing else. Something is still wrong?!?!?

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
  •