Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2012
    Posts
    123
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Arrow Noob...Changing row colors

    I am wanting to change the results of the mysql database row colors. I would like to alternate between rows as they are displayed in my shoutobox. Here is my code:

    Code:
    <?php
    require_once 'cn.php';
    require_once 'protect.php';
    
    $fiveMinutesAgo = time() - 600;
    
    $sql = 'SELECT
    	username, message_content, message_time
    		FROM
    	messages
    		WHERE
    	message_time > ' . $fiveMinutesAgo . '
    		ORDER BY
    	message_time';
    $result = mysql_query($sql, $cn) or
    	die(mysql_error($cn));
    	
    while ($row = mysql_fetch_assoc($result)) {
    	$hoursAndMinutes = date('g:ia', $row['message_time']);
    	
    	echo '<p><strong>' . $row['username'] . '</strong>: <em>(' . $hoursAndMinutes . ')</em> ' . $row['message_content'] . '</p>';
    }
    ?>

  • #2
    Regular Coder
    Join Date
    Feb 2012
    Posts
    123
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Unhappy

    O NO! I have posted here all day, and didn't even think about it. Sorry if it's in the wrong spot. Please move to correct forum if you need to. Sorry again!

    However, it does relate to my other post about ajax/mysql/ etc... Sorry

  • #3
    Regular Coder
    Join Date
    Feb 2012
    Posts
    123
    Thanks
    19
    Thanked 3 Times in 3 Posts
    okay..I've figured out how to do alternating colors, but the tables stretch based on who types the longest sentence, and it makes the usernames go to double lines instead of one line. Is there a way to define the tables so that they are set to a certain length?

    Example:

    Username...... Time..... Message.............................................................

    Also....in my code, it's giving me 2:00am for every post....it never changes....

    Anyone got any ideas? Thank you:

    CODE:
    Code:
    <?php
    require_once 'cn.php';
    require_once 'protect.php';
    
    $fiveMinutesAgo = time() - 600;
    
    $sql = 'SELECT
    	username, message_content, message_time
    		FROM
    	messages
    		WHERE
    	message_time > ' . $fiveMinutesAgo . '
    		ORDER BY
    	message_time';
    $result = mysql_query($sql, $cn) or
    	die(mysql_error($cn));
    
    
    $color="1";
    
    echo '<table width="100%" border="1" align="center" cellpadding="2" cellspacing="0">';
    while($rows=mysql_fetch_array($result)){
    $hoursAndMinutes = date('g:ia', $row['message_time']);
    
    
    if($color==1){
    echo "<tr bgcolor='#CCCCFF'>
    <td>".$rows['username']."</td><td>".$hoursAndMinutes."</td><td>".$rows['message_content']."</td>
    </tr>";
    
    $color="2";
    }
    
    
    else {
    echo "<tr bgcolor='#DFDFDF'>
    <td>".$rows['username']."</td><td>".$hoursAndMinutes."</td><td>".$rows['message_content']."</td>
    </tr>";
    
    
    $color="1";
    }
    
    }
    echo '</table>';
    mysql_close();
    ?>
    Last edited by XCalibre; 03-01-2012 at 12:59 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •