Page 1 of 3 123 LastLast
Results 1 to 10 of 23

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

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

    Cool Displaying Information in more than 1 colour

    I already have a database with information stored in it. And I want to display the information on a webpage using PHP.

    Is it possible to tell it to be displayed with the first letter in one colour and the rest of the word in another colour.

    So, for example, my name on this site is Smithster.

    If this word was stored in a database and I wanted to display it on the webpage in the following format......

    Smithster

    Is this possible and if so, anyone know how to do it?!?!?!?

    Thanks in advance.

    Smithster.

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

    Default

    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>
    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!

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

    Default

    Argh, no! Don't use a separate <span> for every single letter! That's very far from an easiest way, and is ridiculously inefficient.
    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. #4
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Why multiple spans?
    HTML Code:
    <style type="text/css">
    .name {
        color: #48d1cc;
    }
    .name:first-letter {
        color: red;
    }
    </style>
    </head>
    <body>
      <p>
        <span class="name"><?php echo $name; ?></span>
      </p>
    Edit
    Oh, I see why, first-letter pseudo class doesn't work for span (at least not in IE).

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

    Default

    :first-letter doesn't work at all in IE.
    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!

  6. #6
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    It does, it works for <p>.

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

    Default

    Oh no, it does work, but has bugs.
    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!

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

    Default

    ok, so now Im really confused!!! The original coding you posted Twey...will it work in IE or not??? And how do I put it into a PHP script. As when I copy it in as it is, but change the $name to what I need, I just get an error....

    Parse error: syntax error, unexpected '<' in /home/******/public_html/clanapp/challengeus/viewreportwithname.php on line 40

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

    Default

    ok, so now Im really confused!!! The original coding you posted Twey...will it work in IE or not???
    Mine will work fine, yes. It's DimX' that has issues in IE.
    Parse error: syntax error, unexpected '<' in /home/******/public_html/clanapp/challengeus/viewreportwithname.php on line 40
    The script starts from outside PHP parsing mode. That is to say, it should not be within <?php ?> tags.
    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!

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

    Default

    yeah I guessed that!! Have changed it and now the script works again.

    But, I still have to get the variable $name to match up with the name in the database. I thought it would be something like this....

    Code:
    $name = . $row['alias'] .
    But it does not want to work!! So I am 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
  •