Solved

Correct way to style text based on status from database

Posted on 2016-10-08
6
25 Views
Last Modified: 2016-10-08
If something is unread I want to make it bold but if read then it must display as normal (not bold). I just want to know if the way I have done it is okay or perhaps there is a better way?

<?php 
if($read_status == "unread"){
											
   echo "<strong>" . $db_name . "</strong>";
											
      } else {
											
           echo $db_name;
      }

?>

Open in new window

0
Comment
Question by:Black Sulfur
  • 3
  • 2
6 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41835033
Looks OK to me.  Assuming that you have clear data integrity with respect to the value of $read_status, right?
0
 

Author Comment

by:Black Sulfur
ID: 41835040
I have a function called clean_output for db record output

$read_status = clean_output($row['read_status]);

Open in new window


clean_output is basically htmlentities and I think I might have something else in there but can't remember now what it is without going to hunt for it.

Not sure if that is what you meant by clear data integrity?
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41835044
I just meant, "Can you depend on the value of $read_status  to be a true indicator showing whether the information has been read?"

The general problem we face with knowing whether something has been read or not is that unless the client checks a box that says, "I have read this and agree" we have no way of knowing that the information was actually read.  And most of those "I agree" boxes get checked without anyone reading the associated material.  For the most part, once "I agree" (or similar) has been checked you are on firm ground in understanding that the client has accepted whatever terms you're presenting.

It's probably not important, but <strong> and <b> may not have the same style effect.  That will depend on the CSS.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Black Sulfur
ID: 41835052
Oh. No, these aren't for terms and conditions. I have a bootstrap badge that shows the number of unread comments.

Whenever a new comment is added I have a default value of "unread" set. That is how it counts the number of unread comments I have and uses that number to display a bright red badge with a number in it. I have a SQL count that just counts the number of "unread" rows it finds.

I am now about to try figure out how to make it change from "unread" to "read" if I click on the link to the specific comment. But, I guess I could use javascript to help (as you know, I am quite new to the world of web development/programming) and unfortunately don't know very much javascript as of yet. But I could probably find a way of doing it just with PHP. Anyway, that is for another question :)
0
 

Author Comment

by:Black Sulfur
ID: 41835053
PS.

And the bold part is just to help me know what is unread or read. The message subject will be in bold if I have not yet clicked on it.
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41835055
My preference is to do this
$readstatus = ($read_status == "unread") ? "newitem" : "";
echo <<< HTML
  <span class="{$readstatus}">{$db_name}</span>
HTML;

Open in new window

CSS
span.unread {
   font-weight: bold;
}

Open in new window

This gives you much more granular control over how you want to present the read vs unread. It means you can target both the read and unread items for styling and you are not bound into a specific format with a tag like <strong>.
1

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now