Solved

Correct way to style text based on status from database

Posted on 2016-10-08
6
37 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 109

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 109

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 54

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

822 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