HexxNine
HexxNine

Reputation: 456

How do I add font color to my query result

I have a MySQL statement that returns hyper linked text. I now need it to display as blue text to show it is a link.

SELECT CONCAT('<a href="', opencourseware.website_url, '">', opencourseware.website_name, '</a><br />') AS Link

Basically I need to add this HTML somehow

<font color="blue">This is some text!</font>

It Seems like it should be so easy but I just can't get it working :( any help would be greatly appreciated!

Upvotes: 0

Views: 12273

Answers (3)

nhavar
nhavar

Reputation: 198

There are a couple of different options. The first is to just add a class to the anchor and then put add an entry to your existing CSS file

SELECT CONCAT('<a href="', opencourseware.website_url, '" class="openCourseURL">'

and then in your CSS file for your page add (PREFERRED)

.openCourseURL{color: blue;}

or if you don't have a separate CSS file, add this to the head of your HTML document (NOT PREFERRED).

<style type="text/css>
    .openCourseURL{color: blue;}
</style>

OR you can use an inline style (but it's not considered best practice due to maintenance and rebranding concerns) (REALLY NOT PREFERRED)

SELECT CONCAT('<a href="', opencourseware.website_url, '" style="color:blue">'

NOTE: Typically in a web app we would like to see SQL used to get the data but not generating the HTML. HTML generation should be happening within a template engine like JSP, PHP, Handlebars, Dust, etc., as best practice.

Upvotes: 0

JasonSec
JasonSec

Reputation: 634

SELECT CONCAT('<a style="color:blue;" href="', opencourseware.website_url, '">', opencourseware.website_name, '</a><br />') AS Link

Just know most browsers will display links as blue anyway ~(-_-)~

Upvotes: 1

ʰᵈˑ
ʰᵈˑ

Reputation: 11375

I have a MySQL statement that returns hyper linked text.

Why not use CSS?

a {
 color: #3452C9;
}

Also, refer to Kevin B's comment; "seems weird to me to generate html with sql"

Upvotes: 0

Related Questions