colouring a certain word in a <TD>

  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post July 5th, 2004, 5:14 am

hey i have a database wars table (phpmyadmin) and in there will be either one of the 3 options:

win
lose
draw

What i want to be able to do is highlight the word "win" in red, lose in blue etc...
I want this to be done in css so its easily updatable as i have a text box in the admin area where i can edit my cascading stylesheet.
I tried to also do this in php, preview (snippet) below:

PHP Code: [ Select ]
 
$colarray = array(
 
    'win' => 'red',
 
    'lose' => 'draw',
 
    'draw' => 'yellow'
 
);
 
 
 
echo "<TD bgcolor=006699>";
 
echo '<span style="color:'.$colarray[$myrow['winlose']].'">'.$myrow['winlose'].'</span>';
 
echo "$myrow["winlose"]";
 
}
 
 
  1.  
  2. $colarray = array(
  3.  
  4.     'win' => 'red',
  5.  
  6.     'lose' => 'draw',
  7.  
  8.     'draw' => 'yellow'
  9.  
  10. );
  11.  
  12.  
  13.  
  14. echo "<TD bgcolor=006699>";
  15.  
  16. echo '<span style="color:'.$colarray[$myrow['winlose']].'">'.$myrow['winlose'].'</span>';
  17.  
  18. echo "$myrow["winlose"]";
  19.  
  20. }
  21.  
  22.  


but still no luck.
Any ideas, for php, or even better css?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 5th, 2004, 5:14 am

  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Mar 24, 2004
  • Posts: 1855
  • Loc: Uk
  • Status: Offline

Post July 5th, 2004, 5:30 am

PHP Code: [ Select ]
 
echo "<td bgcolor=006699 class='" . $myrow['winlose'] . "'>";
 
echo $myrow['winlose'];
 
echo "</td>";
 
 
  1.  
  2. echo "<td bgcolor=006699 class='" . $myrow['winlose'] . "'>";
  3.  
  4. echo $myrow['winlose'];
  5.  
  6. echo "</td>";
  7.  
  8.  


outputs (with a win for eg):
Code: [ Select ]
<td bgcolor=006699 class='win'>win</td>


Then use css:
Code: [ Select ]
td.win {color:#F00;}
td.lose{color:#0F0;}
td.draw{color:#00F;}
  1. td.win {color:#F00;}
  2. td.lose{color:#0F0;}
  3. td.draw{color:#00F;}


and just edit the css to change colours.
CSS website design tutorials
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post July 5th, 2004, 5:34 am

i dont understand this bit:

PHP Code: [ Select ]
echo "<td bgcolor=006699 class='" . $myrow['winlose'] . "'>";
 
echo $myrow['winlose'];
 
echo "</td>";
  1. echo "<td bgcolor=006699 class='" . $myrow['winlose'] . "'>";
  2.  
  3. echo $myrow['winlose'];
  4.  
  5. echo "</td>";


why is the class named as being " . $myrow['winlose'] ." ???? How will it know what each colour for each word needs to be?
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Mar 24, 2004
  • Posts: 1855
  • Loc: Uk
  • Status: Offline

Post July 5th, 2004, 5:41 am

From the css class selectors.

I have made the assumptions that:

$myrow['winlose'] is either "win", "lose" or "draw"
You only want the text "win", "lose" or "draw" in the cell.

Are these assumptions wrong?
CSS website design tutorials
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post July 5th, 2004, 5:43 am

nah not the words, you assumed right... its the way it works that has confused me.

Because i wont be inputting the words, it will be coming from a database table that will be put in to the database via a form.

Then it has an output.... in a TD.

I want it to be done automatically....
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Mar 24, 2004
  • Posts: 1855
  • Loc: Uk
  • Status: Offline

Post July 5th, 2004, 5:48 am

well your code used:
PHP Code: [ Select ]
 
$colarray[$myrow['winlose']]
 
 
  1.  
  2. $colarray[$myrow['winlose']]
  3.  
  4.  


which would require $myrow['winlose'] to be "win", "lose" or "draw", because of the array indexes you chose for $colarray

It all depends on the values you have in the database.

Is this (roughly) what you are trying to output, or am I confused:
http://www.caffeinefuelled.net/richard- ... rtable.htm
CSS website design tutorials
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post July 5th, 2004, 5:50 am

yeppp thats it

let me play around with it, i let you know results as soon as it works/not works.. or whatever :oops:
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Mar 24, 2004
  • Posts: 1855
  • Loc: Uk
  • Status: Offline

Post July 5th, 2004, 5:52 am

Thats what the code above will (should - not tested) output, look at the source code for that page.

basically, you output win lose or draw into the cell, and you output the same string for the class. The css will do the rest.
CSS website design tutorials
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post July 5th, 2004, 5:53 am

oh... perfect... thanks!!!
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post July 5th, 2004, 5:56 am

im still stuck on the communication that is going on between the css and the

PHP Code: [ Select ]
 
echo "<td bgcolor=006699 class='" . $myrow['winlose'] . "'>";
 
echo $myrow['winlose'];
 
 
  1.  
  2. echo "<td bgcolor=006699 class='" . $myrow['winlose'] . "'>";
  3.  
  4. echo $myrow['winlose'];
  5.  
  6.  


as im NOT(edited) use to php, when i use a class i make it "td.win" as in your example. But the class here is referring to the echo below it... but how does the css know which class the td needs?

i know it works and i shouldnt be bothered but at occasions like this i do get a bit .... :S
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Mar 24, 2004
  • Posts: 1855
  • Loc: Uk
  • Status: Offline

Post July 5th, 2004, 6:07 am

The css doesn't care about the PHP, just the <b>outputted html</b>. In the outputted html:
Code: [ Select ]
<td bgcolor=006699 class='win'>win</td>


the td is of class 'win'. The css rule says:

Quote:
If a td element has the className "win", then make all of the text <b>inside</b> the td element red.


"inside the td" means enclosed within the < td > and </ td > tags. I'd check up on your css basics if I were you, w3schools is a good place to start.
CSS website design tutorials
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post July 5th, 2004, 6:09 am

ohhh, thanks rtm.. yeah i been making most of this site on css, and i must admit it is a very useful piece of web programming..

I will be learning more on the css. Thank you for the resource
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 102 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.