0

I'm trying to create an email-like system where read messages appear normal and new entries/messages appear in bold. I created a css rule to meet the text formatting, but the problem i'm having is implementing it on my loop.

thanks

        $stmt = $pdo->query("SELECT * FROM $tbl_name");
        $stmt->execute();
        $num_rows = $stmt->rowCount();
        print "<p>$num_rows Record(s) Found.</p>";

        echo "<table width='100%' border='1' bordercolor='#0cc' cellspacing='0' cellpadding='2'>";
        echo "<tr>
        <th bgcolor='#444444' align='center'><font color='#fff'>Surname</font></th>
        <th bgcolor='#444444' align='center'><font color='#fff'>Firstname</font></th>
        <th bgcolor='#444444' align='center'><font color='#fff'>Email / Username</th>
        <th bgcolor='#444444' align='center'><font color='#fff'>Phone</th>
        <th bgcolor='#444444' align='center'><font color='#fff'>Date Registered</th>
        <th bgcolor='#444444' align='center'><font color='#fff'>Status</th>
        <th bgcolor='#444444' align='center'><font color='#fff'>Create Account</th>
        <th bgcolor='#444444' align='center'><font color='#fff'>Delete Account</th>
        </tr>";
        // keeps getting the next row until there are no more to get
        while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

        $clas = $row['entry'];
        if($clas == 'NEW'){
        $style = "<div style='font-weight:bold'></div>";
        }else{
        $style = "<div style='font-weight:normal'></div>";    
        }

        // Print out the contents of each row into a table
        echo "<tr><td>";
        echo ucfirst($row['surname']);
        echo "</td><td>";
        echo ucfirst($row['firstname']);
        echo "</td><td>";
        echo $row['email'];
        echo "</td><td>";
        echo $row['phone'];
        echo "</td><td>";
        echo $row['today'];
        echo "</td><td>";
        echo $row['status'];
        echo "</td><td>";
        echo "<a href='create-account.php?id={$row['id']}'>Create Account</a>";
        echo "</td><td>";
        echo "<a href='account-delete.php?id={$row['email']}'>Delete Account</a>";
        echo "</td></tr>";
        }
        echo "</table>";
Chidi
  • 35
  • 4

1 Answers1

1

That's probably what you want to achieve, but please ask proper question next time.

while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

  $clas = $row['entry'];
  if($clas == 'NEW'){
    $style = ' style="font-weight:bold"';
  }

  // Print out the contents of each row into a table
  echo "<tr{$style}><td>";
  echo ucfirst($row['surname']);
  echo "</td><td>";
  echo ucfirst($row['firstname']);
  echo "</td><td>";
  echo $row['email'];
  echo "</td><td>";
  echo $row['phone'];
  echo "</td><td>";
  echo $row['today'];
  echo "</td><td>";
  echo $row['status'];
  echo "</td><td>";
  echo "<a href='create-account.php?id={$row['id']}'>Create Account</a>";
  echo "</td><td>";
  echo "<a href='account-delete.php?id={$row['email']}'>Delete Account</a>";
  echo "</td></tr>";
}
Forien
  • 2,712
  • 2
  • 13
  • 30
  • Thanks but didnt work as intended. What i want is for the row that meets the NEW condition to be bold but what you did, all becomes bold regardless of the condition – Chidi Feb 02 '15 at 12:51
  • Thanks. I finally got it right. Without the else condition it wouldnt work. When i added the else condition, it reeled out just what i wanted. I didnt know how to apply the styling but now i know how to. sorry if you deemed it an improper question, but it was difficult to me until you did it! – Chidi Feb 02 '15 at 13:00