Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Wednesday, November 11, 2026
About Us
Magazine
Open Source
CVS
Services
Index  »  Projects  »  phpMyEdit  »  Forum  »  Color Coding output question

phpMyEdit General     Color Coding output question
Post new topic   Reply to topic    
 
ARADTech     Joined: 03 Oct 2004   Posts: 3  
Post Posted: 2004-10-03 21:20
Back to top  Reply with quote     

Ok here is what I want to do and I have no idea how it is best to achieve this.

In my table I have a enum field that has these 3 status's
AVAIL , PENDING , SOLD.

What I am trying to achieve is to have the page show a different color in the view for each of those status's so for instance the AVAIL would show up green , the PENDING yellow, and the SOLD red.

Any help would be much appreciated , please and thank you in advance :)

Peace and Creativity
Chris

 
ARADTech     Joined: 03 Oct 2004   Posts: 3  
Post Posted: 2004-10-03 22:56
Back to top  Reply with quote     

Code:
$opts['fdd']['status'] = array(
  'name'     => 'Status',
  'select'   => 'T',
  'escape'     => false,
  'maxlen'   => 7,
  'values'   => array(
                  "avail",
                  "pending",
                  "sold"),
  'default'  => 'avail',
  'sort'     => true
);

$opts['fdd']['status']['sql|LF'] =
  'if( status = "sold",
   CONCAT("<span style=\"color:red\">",
   status, "</span>"), status )';


This will color code the status to red, how do I make it do the rest ?

Any help is much appreciated :)

Peace and Creativity
Chris

 
ajh     Joined: 17 Dec 2003   Posts: 236  
Post Posted: 2004-10-04 22:07
Back to top  Reply with quote     

How about:
Code:

$opts['fdd']['status']['sql|LF'] =
  'CONCAT("<span style=\"color:",
     CASE status
        WHEN "sold" THEN "red"
        WHEN "pending" THEN "yellow"
        ELSE "green"
     END,
    "\">", status, "</span>")';


You need to check the exact syntax as I've probably introduced a typo...for your ref, this is the page in the MySQL manual:
http://dev.mysql.com/doc/mysql/en/Control_flow_functions.html

 
ARADTech     Joined: 03 Oct 2004   Posts: 3  
Post Posted: 2004-10-05 00:18
Back to top  Reply with quote     

Thanks bro that worked perfect, much appreciated!

Peace and Creativity
Chris

 
bentuinstra     Joined: 12 Sep 2004   Posts: 29  
Post Posted: 2005-02-16 10:41
Back to top  Reply with quote     

Hi,

I would like to do something with background color of a date field. I use this code:

Code:
$opts['fdd']['DUEDATE'] = array(
  'name'     => 'DUEDATE',
   'escape'     => false,
  'select'   => 'T',
  'calendar' => true,
  'maxlen'   => 10,
  'sort'     => true,
  'sql|LF'  =>  'CONCAT("<span style=\"background-color:",
    CASE PMEtable0.DUEDATE
      WHEN PMEtable0.DUEDATE<CURDATE() THEN "ffaa00"
        ELSE "#aaff00"     
   END,
    "\">", PMEtable0.DUEDATE, "</span>")'
);


The color always goes for the "ELSE" option, what do I do wrong?

Kind regards,

Ben

 
ajh     Joined: 17 Dec 2003   Posts: 236  
Post Posted: 2005-02-16 10:54
Back to top  Reply with quote     

Try this:

Code:
$opts['fdd']['DUEDATE'] = array(
  'name'     => 'DUEDATE',
   'escape'     => false,
  'select'   => 'T',
  'calendar' => true,
  'maxlen'   => 10,
  'sort'     => true,
  'sql|LF'  =>  'CONCAT("<span style=\"background-color:",
    IF(PMEtable0.DUEDATE<CURDATE(),"#ffaa00","#aaff00"),
    "\">", PMEtable0.DUEDATE, "</span>")'
);


Again - check the syntax in the MySQL manual

 
bentuinstra     Joined: 12 Sep 2004   Posts: 29  
Post Posted: 2005-02-16 12:51
Back to top  Reply with quote     

Hi AJH,

This works fine. (Syntax oke ;-)

But it has a strange side effect. Since I sort on the dued[img]ate I now see that the records who are overdue (duedate<curdate) are sorted below the other records.

Do you have any idea what is happening here?

kind regards,

Ben

 
bentuinstra     Joined: 12 Sep 2004   Posts: 29  
Post Posted: 2005-02-16 12:55
Back to top  Reply with quote     

Found the solution.

It seems that the sorting is done on the whole field (including colorcode). Since the colorcode is earlier in the field....

So I have to change colors ;-)

Cheers Ben

 
ajh     Joined: 17 Dec 2003   Posts: 236  
Post Posted: 2005-02-16 14:47
Back to top  Reply with quote     

If you want the correct sort sequence, why don't you put an HTML comment just before the SPAN with the field data in it. That should fool PME:

Code:

'sql|LF' => 'CONCAT("<!-- ",PMEtable0.DUEDATE,"--><span style=\"background-color:", IF(PMEtable0.DUEDATE<CURDATE(),"#ffaa00","#aaff00"),
    "\">", PMEtable0.DUEDATE, "</span>")'


PME will sort on whatever is in the comment, but will display whatever is in the SPAN.

 
bentuinstra     Joined: 12 Sep 2004   Posts: 29  
Post Posted: 2005-02-18 09:53
Back to top  Reply with quote     

I will test this next monday,

Kind regards Ben

 
bentuinstra     Joined: 12 Sep 2004   Posts: 29  
Post Posted: 2005-02-24 13:07
Back to top  Reply with quote     

Hi AJH,

Yhis code works fine, exactly like I wanted it to do,

Thanks a lot for your time and support,

Ben

 
westdesign     Joined: 20 Nov 2006   Posts: 2  
Post Posted: 2007-09-19 13:28
Back to top  Reply with quote     

bentuinstra wrote:
Hi AJH,

Yhis code works fine, exactly like I wanted it to do,

Thanks a lot for your time and support,

Ben


At the actualy version is something changed ? I try in all the ways using the codes above, but I can't coloring in different way some value.
The <span.... code are displayed like text in the page... and is not change the style...

I think something if filtering the html codes....
Any help ?!
Thanx in advance...

 
bentuinstra     Joined: 12 Sep 2004   Posts: 29  
Post Posted: 2007-09-19 14:20
Back to top  Reply with quote     

Hi Westdesign,

This is the code I use:

Code:
$opts['fdd']['DATUMGEREED'] = array(
  'name'     => 'GEREED',
  'select'   => 'T',
'calendar' => true,
  'nowrap' => true,
  'maxlen'   => 10,
  'escape' => false,
'sql|LF'  =>  'CONCAT("<span style=\"background-color:",
    IF(PMEtable0.DATUMGEREED<=CURDATE(),"yellow","white"),
    "\">", PMEtable0.DATUMGEREED, "</span>")',
'sort'     => true
);


Hope this example helps.

The escape line is important.

Kind regards,

Ben

 
franciscohm     Joined: 08 May 2008   Posts: 33  
Post Posted: 2008-05-09 12:33
Back to top  Reply with quote     

Hi all,

I do not know why (maybe because I am using MySQL 5.1)

The expression CASE does not work for me like in:

Code:
$opts['fdd']['provider']['sql|LF'] = 'CONCAT("<span style=color:", SELECT CASE WHEN provider="Ferrari" THEN "red"  ELSE "green"  END CASE,">", provider, "</span>")';


However the expression IF works fine, like in:

Code:
$opts['fdd']['provider']['sql|LF'] = 'if( provider= "Ferrari", CONCAT("<span style=\"color:red\"><b>", provider, "</b></span>"), if( provider= "BMW", CONCAT("<span style=\"color:blue\"><b>", provider, "</b></span>"),provider))';


Maybe this is of interest for anyboy else... :-)

 
Post new topic   Reply to topic    

Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top · Feedback form · Application form
Report bug on PLATON.SK website · Terms of use · Privacy policy