943,641 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 942
  • PHP RSS
Jan 29th, 2009
0

HEX colours from mySQL to PHP (in colour)

Expand Post »
Heyy, need some help here.

ok, I've got my script here right.
PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <head><title>Display Records</title>
  3. <style type="text/css">
  4. td {font-family: tahoma, arial, verdana; font-size: 10pt }
  5. </style>
  6.  
  7.  
  8. </head>
  9. <body>
  10. <?php
  11. $db="aseco121";
  12. $link = mysql_connect('127.0.0.1: 3306', 'root', '******');
  13. if (! $link)
  14. die(mysql_error());
  15. mysql_select_db($db , $link)
  16. or die("Couldn't open $db: ".mysql_error());
  17. $result = mysql_query( "SELECT * FROM players ORDER BY Login" )
  18. or die("SELECT Error: ".mysql_error());
  19. $num_rows = mysql_num_rows($result);
  20. print "There are $num_rows records.<P>";
  21.  
  22. print "<table width=200 border=1>\n";
  23. while ($get_info = mysql_fetch_row($result)){
  24. print "<tr>\n";
  25. foreach ($get_info as $field)
  26. print "\t<td>$field</td>\n";
  27. print "</tr>\n";
  28. }
  29. print "</table>\n";
  30. mysql_close($link);
  31. ?>
  32. <br>
  33.  
  34. </body>
  35. </html>

and it comes out with my tables okay?
bieing:
+----+--------+-------------------------+
| 76 | .enjo. | $i$0f0N$000R$ff0G |
+----+--------+-------------------------+
---- table goes on -----

and this '$i' thing is like trackmania font coosing
so $i$0f0N$000R$ff0G would turn out to be NRG (green N, Black R, Yellow G)

note that thier are tonnes of combonations i dont want to write each on out. so how would i get to remove the $ format codes and replace them with things that work in html/php?

so instead of '$F00MAXICUBE' i want MAXICUBE

colour table: http://tutorials.tm-creative.org/gen...ours/index.php
Reputation Points: 10
Solved Threads: 0
Light Poster
maxicube is offline Offline
32 posts
since Nov 2008
Jan 29th, 2009
0

Re: HEX colours from mySQL to PHP (in colour)

anybody got any suggestions?
Reputation Points: 10
Solved Threads: 0
Light Poster
maxicube is offline Offline
32 posts
since Nov 2008
Jan 29th, 2009
0

Re: HEX colours from mySQL to PHP (in colour)

Hi Maxicube - that's some interesting code on trackmania. Haven't seen that type of encoding before.

Can you give more details about how this is going to be used?


For the DB example:
The only thing I can think of is chopping up the string into bits using explode on the '$' character. You know your last chunk is the yellow, penultimate is black and the previous one is yellow. Any bits left over can be compared with a simple array to get the right format (e.g. $i%s -> <em>%s</em>).

If Just colours:
Each example uses the $ + 3 hexadecimal chars. You can use the FONT tag and add a 'color' attribute - but this is bad. A span tag with the 'color' attribute would be more acceptable, although a 'class' attribute linked to a CSS file would be really good. How you'd do the latter I'm not sure as each color would probably require its own class name - bit awkward.

So: $f00MAXICUBE turns to <span color="#ff0000">MAXICUBE</span>

Basically you need to double each hex character and relpace the $ with a #, surround the text part with span tags and insert a color attribute.

Personally, I'd write a function something like this (it's a bit dirty - all the substr!):

PHP Syntax (Toggle Plain Text)
  1. function colorize($tmString){
  2. $colorhex = '#' . substr($tmString,1,1) . substr($tmString,1,1) . substr($tmString,2,1) . substr($tmString,2,1) . substr($tmString,3,1) . substr($tmString,3,1);
  3. $string = substr($tmString,4);
  4. $output = "<span color=\"{$colorhex}\">{$string}</span>";
  5. return $output;
  6. }

USAGE:
PHP Syntax (Toggle Plain Text)
  1. $txt = "$f00MAXICUBE";
  2. echo "I went to a bar and saw " . colorize($txt) . " drinking a soda...";

Don't know if that's any use?
Sponsor
Featured Poster
Reputation Points: 1046
Solved Threads: 943
Sarcastic Poster
ardav is offline Offline
6,671 posts
since Oct 2006
Jan 29th, 2009
0

Re: HEX colours from mySQL to PHP (in colour)

Thinking about it, you may be better off just placing the hex+string directly into html and using a javascript function to read the whole document (onload), find the hex codes and convert them all
Sponsor
Featured Poster
Reputation Points: 1046
Solved Threads: 943
Sarcastic Poster
ardav is offline Offline
6,671 posts
since Oct 2006
Jan 30th, 2009
0

Re: HEX colours from mySQL to PHP (in colour)

umm, ill give u my table here:
http://phxscape.servegame.com/testin...ay_records.php
and this is how its used:
http://www.tm-forum.com/viewtopic.php?t=1767

thanks for replying, umm, seeing im not realy uptoscratch with javascript, how would i do that? *sigh*

example looks nice
Last edited by maxicube; Jan 30th, 2009 at 3:29 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
maxicube is offline Offline
32 posts
since Nov 2008
Jan 30th, 2009
0

Re: HEX colours from mySQL to PHP (in colour)

This is good stuff!
You'd have to check for these first, then apply the colorize() function.

PHP Syntax (Toggle Plain Text)
  1. $i: italic equivalent to <em></em>
  2. $s: shadowed ??
  3. $w: wide CSS class letter spacing?
  4. $n: narrow as above
  5. $m: normal normal what?
  6. $g: default color can be set via CSS
  7. $o: bold <strong></strong>
  8. $z: reset all this could be tricky
  9. $t: Changes the text to capitals CSS class Capitalize
  10. $$: Writes a dollarsign

I don't know how you'd do shadowed, but most of the others can be set with CSS classes or inline html tags. You could change all of the above to span classes, e.g. <span class = "i o w">TEXT</span> for
$i$o$wTEXT .

With your CSS:

PHP Syntax (Toggle Plain Text)
  1. i{
  2. font-style:italic;
  3. }
  4. o{
  5. font-weight:bold;
  6. }
  7. w{
  8. letter-spacing:2em;
  9. }
Sponsor
Featured Poster
Reputation Points: 1046
Solved Threads: 943
Sarcastic Poster
ardav is offline Offline
6,671 posts
since Oct 2006
Mar 3rd, 2009
0

Re: HEX colours from mySQL to PHP (in colour)

heh, nice work sir, i tink ill post this as solved. +rep
Reputation Points: 10
Solved Threads: 0
Light Poster
maxicube is offline Offline
32 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: WHERE ( SELECT COUNT(*) FROM table2 WHERE fbid = *current_row_primary_key*) > 150
Next Thread in PHP Forum Timeline: Warning: session_start()





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC