Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Correct way to style text based on status from database

Posted on 2016-10-08
6
Medium Priority
?
63 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 59

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

670 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