Solved

Correct way to style text based on status from database

Posted on 2016-10-08
6
53 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 110

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
 
LVL 1

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 110

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

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
 
LVL 1

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 57

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn how to dynamically set the form action using jQuery.

752 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