HEX colours from mySQL to PHP (in colour)

Thread Solved

Join Date: Nov 2008
Posts: 18
Reputation: maxicube is an unknown quantity at this point 
Solved Threads: 0
maxicube maxicube is offline Offline
Newbie Poster

HEX colours from mySQL to PHP (in colour)

 
0
  #1
Jan 29th, 2009
Heyy, need some help here.

ok, I've got my script here right.
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 18
Reputation: maxicube is an unknown quantity at this point 
Solved Threads: 0
maxicube maxicube is offline Offline
Newbie Poster

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

 
0
  #2
Jan 29th, 2009
anybody got any suggestions?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 989
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 129
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

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

 
0
  #3
Jan 29th, 2009
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!):

  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:
  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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 989
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 129
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

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

 
0
  #4
Jan 29th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 18
Reputation: maxicube is an unknown quantity at this point 
Solved Threads: 0
maxicube maxicube is offline Offline
Newbie Poster

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

 
0
  #5
Jan 30th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 989
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 129
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

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

 
0
  #6
Jan 30th, 2009
This is good stuff!
You'd have to check for these first, then apply the colorize() function.

  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:

  1. i{
  2. font-style:italic;
  3. }
  4. o{
  5. font-weight:bold;
  6. }
  7. w{
  8. letter-spacing:2em;
  9. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 18
Reputation: maxicube is an unknown quantity at this point 
Solved Threads: 0
maxicube maxicube is offline Offline
Newbie Poster

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

 
0
  #7
Mar 3rd, 2009
heh, nice work sir, i tink ill post this as solved. +rep
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC