1

Title is not entirely clear what is required if more detail is: In mysql db table has, from it to the page of data is displayed in html table this code:

<?php            
   $db_host = 'localhost';         
   $db_name = 'DB';         
   $db_username = 'NAME';         
   $db_password = 'PASS';       
   $db_table_to_show = 'TABLE';         
   $connect_to_db = mysql_connect($db_host, $db_username, $db_password) 
   or die("Could not connect: " . mysql_error());           
   mysql_select_db($db_name, $connect_to_db)      
   or die("Could not select DB: " . mysql_error());   
   mysql_set_charset("utf8");          
   $qr_result = mysql_query("select * from " . $db_table_to_show)      
   or die(mysql_error());            
   echo '<table id="table">';       
   echo '<thead>';         
   echo '<tr>';
   echo '<th class="table-fandom">fandom</th>';        
   echo '<th>author</th>';     
   echo '<th class="table-name">name</th>';
   echo '<th>size</th>';    
   echo '<th class="table-status">status</th>';             
   echo '<th>date</th>';       
   echo '<th>tags</th>';
   echo '</tr>';       
   echo '</thead>';        
   echo '<tbody>';         

   while($data = mysql_fetch_array($qr_result)){       
       echo '<tr>';
       echo '<td>' . $data['fandom'] . '</td>';    
       echo '<td>' . $data['author'] . '</td>';         
       echo '<td><a href="/goto/' . $data['url'] . '" target="_blank">' . $data['name'] . '</a><div class="menu" style="display: none;"><br> '                                             . $data['annotation'] .  '  </div></td>';       
       echo '<td>' . $data['size'] . '</td>';  
       echo '<td>' . $data['status'] . '</td>';        
       echo '<td>' . $data['date'] . '</td>';  
       echo '<td>' . $data['tags'] . '</td>';                  
       echo '</tr>';       
   }       

   echo '</tbody>';        
   echo '</table>';         
   mysql_close($connect_to_db);        
  ?>

Requires that the new records that were added today, has been assigned a special css class within 72 hours. PS Sorry for my english, it's not my native language.

3
  • Which thing you want to add css class to the table or to the whole row which is added today means tr of the row added today or every td of row which is added today? Commented Mar 13, 2015 at 9:54
  • add something like this if($date['frommysql'] == $currentDate) Commented Mar 13, 2015 at 9:57
  • @Neeraj Kumar I want to add a class to the tr. But it is possible to td, like author. Commented Mar 13, 2015 at 10:25

2 Answers 2

1

You can do this:

...
 while($data = mysql_fetch_array($qr_result)){     
      if($data['date'] > date('Y-m-d', strtotime('-3 days'))  
          echo '<tr class="new">';
      else
          echo '<tr>';

      echo '<td>' . $data['fandom'] . '</td>';    
      echo '<td>' . $data['author'] . '</td>';         
      echo '<td><a href="/goto/' . $data['url'] . '" target="_blank">' .         $data['name'] . '</a><div class="menu" style="display: none;"><br> '         . $data['annotation'] .  '  </div></td>';       
      echo '<td>' . $data['size'] . '</td>';  
      echo '<td>' . $data['status'] . '</td>';        
      echo '<td>' . $data['date'] . '</td>';  
      echo '<td>' . $data['tags'] . '</td>';                  
      echo '</tr>';       
    } 
Sign up to request clarification or add additional context in comments.

Comments

0

First you need to add registration time in table. For example you save registration time in unix timestamp. Then you need to use condition after while loop.

 while($data = mysql_fetch_array($qr_result))
 { 
    if($data['registration_time'] > strtotime("-3 days") ) 
    {
      echo '<tr class="change_color_class">';
    }
    else
    {
          echo '<tr class="normal_class">';
    }        
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.