Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-01-2012, 09:49 AM   PM User | #1
XCalibre
Regular Coder

 
Join Date: Feb 2012
Posts: 121
Thanks: 19
Thanked 3 Times in 3 Posts
XCalibre has a little shameless behaviour in the past
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>';
}
?>
XCalibre is offline   Reply With Quote
Old 03-01-2012, 09:51 AM   PM User | #2
XCalibre
Regular Coder

 
Join Date: Feb 2012
Posts: 121
Thanks: 19
Thanked 3 Times in 3 Posts
XCalibre has a little shameless behaviour in the past
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
XCalibre is offline   Reply With Quote
Old 03-01-2012, 11:19 AM   PM User | #3
XCalibre
Regular Coder

 
Join Date: Feb 2012
Posts: 121
Thanks: 19
Thanked 3 Times in 3 Posts
XCalibre has a little shameless behaviour in the past
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..
XCalibre is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:30 AM.


Advertisement
Log in to turn off these ads.