Solved

Correct way to style text based on status from database

Posted on 2016-10-08
6
49 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 56

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Integrating blogs between to separate WordPress websites 4 27
Change a button after e-mail 4 20
Session on Html 8 39
Table doesn't show the lines! 3 24
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

756 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