/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] color <tr> based on mySQL entry?

I know there’s got to be a way to do this… basically I want to color each <tr> on a table I am outputting simple db query. So in this case… I have a row called category and I want each of the six to kick out a different $row_color I put down some rough notes on what I thought might work??

Anyone have any ideas? My brain is in coast mode and I can’t figure it out… Many thanks to any direction at all!

if($row[‘category’] == “photography”){
$row_color = “FFCC66”;
}elseif{
and so on for the remaining 5….

am I way off?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ZiplineMay 12.2006 — I would stick all six hex values in an array and for each row in your while() change your array key.
Copy linkTweet thisAlerts:
@thunder77authorMay 12.2006 — whoa... way over my head. lol can you break it down to retard talk?
Copy linkTweet thisAlerts:
@cohesiveMay 12.2006 — If it was me, I'd store the colour in the "category" table (if you have one) and then fetch that colour in your query: ie:

[CODE]

SELECT mytable.*, category.color
FROM mytable, category
WHERE mytable.category = category.name

[/CODE]


Then all you would need to do is grab the colour value from the array returned by the query. This also allows for you to add more categories or change their colours without adding or changing your PHP code.

[code=php]$row_color = $row['color'];[/code]
Copy linkTweet thisAlerts:
@UltimaterMay 12.2006 — Zipline means to factor your if, elseif, elseif... statement from:
<i>
</i>if($row['category'] == "photography"){
$row_color = "FFCC66";
}elseif{
and so on for the remaining 5....

into:
<i>
</i>$rowColors=array(
"photography" =&gt; "FFCC66",
[color=blue]"electronics" =&gt; "CCFF22",
"personal" =&gt; "EE00DD",
"contacts" =&gt; "DDEE22",
"other" =&gt; "225577"[/color]
);
$row_color=$rowColors[$row['category']];
Copy linkTweet thisAlerts:
@thunder77authorMay 12.2006 — Thanks for the help, but I can't seem to get it to work?? It's returning the html like there's no hex code at all... any suggestions?
Copy linkTweet thisAlerts:
@cohesiveMay 12.2006 — sounds like you're forgetting the # in front of the hex value eg:

#23DF78
Copy linkTweet thisAlerts:
@thunder77authorMay 12.2006 — that's it! perfecto. thanks all.
×

Success!

Help @thunder77 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...