Colour Problems...
Moderator: General Moderators
Colour Problems...
This is really a question out of curiosity but you know on a website where each setion of the news is a different colour, like:
<tr><td bgcolor='#eeeeee'>
News Section 1...
<tr><td bgcolor='#ffffff'>
News Section 2...
Well I was trying to do that with the php code:
while (true)
{
$row = mysql_fetch_assoc($result);
if ($row == false) break;
echo "<tr bgcolor='#eeeeee'>";
echo "<b>".$row['news']."<br></b>";
}
But I cannot get it to add colour #ffffff for the next section of the news. Its hard to explain this but is it possible...
Joe
<tr><td bgcolor='#eeeeee'>
News Section 1...
<tr><td bgcolor='#ffffff'>
News Section 2...
Well I was trying to do that with the php code:
while (true)
{
$row = mysql_fetch_assoc($result);
if ($row == false) break;
echo "<tr bgcolor='#eeeeee'>";
echo "<b>".$row['news']."<br></b>";
}
But I cannot get it to add colour #ffffff for the next section of the news. Its hard to explain this but is it possible...
Joe
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$colors = array('eeeeee','ffffff');
$cnt = 0;
while($row = mysql_fetch_assoc($result))
{
echo "<tr bgcolor="#{$colors[$cnt]}">";
echo "<td><b>{$row['news']}<br /></b></td></tr>";
$cnt++;
$cnt %= sizeof($colors);
}- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Colour Problems...
The way I do it is
EDIT: grr everyone is owning me today
Code: Select all
<?
$i=1;
while ($row = mysql_fetch_assoc($result))
{
if ($i % 2) == 0 { $bg="#ffffff";}else
{ $bg="#eeeeee";}
echo "<tr bgcolor=".$bg.">";
echo "<b>".$row['news']."<br></b>";
$i++;
}
?>Well now I am having a problem yet again! I have tried everything with this colour project but just cannot seem to beat it. It only shows one colour (#eeeeee) and all of the news articles are running from ID #1. My code is:
$sql = "SELECT * FROM news ORDER BY ID";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$headline = $row['headline'];
$username1 = $row['username'];
$mainnews = $row['mainnews'];
$date = $row['date'];
$i = 1;
$j = $i % 2;
while ($row = mysql_fetch_assoc($result))
{
if ($j == 0)
$bg = "#e1e1e1";
else
$bg = "#eeeeee";
echo "<tr><td bgcolor=".$bg.">";
echo "<font face='verdana' size=1>";
echo "<b>.:$headline:.</b> Posted By: $username1 - <i>$date</i><br><hr color='black'>";
echo "$mainnews<p>";
echo "<a href='changes/edit4.php'>Edit Post</a> ";
echo "</td></tr>";
}
Any help appreciated!
$sql = "SELECT * FROM news ORDER BY ID";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$headline = $row['headline'];
$username1 = $row['username'];
$mainnews = $row['mainnews'];
$date = $row['date'];
$i = 1;
$j = $i % 2;
while ($row = mysql_fetch_assoc($result))
{
if ($j == 0)
$bg = "#e1e1e1";
else
$bg = "#eeeeee";
echo "<tr><td bgcolor=".$bg.">";
echo "<font face='verdana' size=1>";
echo "<b>.:$headline:.</b> Posted By: $username1 - <i>$date</i><br><hr color='black'>";
echo "$mainnews<p>";
echo "<a href='changes/edit4.php'>Edit Post</a> ";
echo "</td></tr>";
}
Any help appreciated!
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
<?php
$sql = "SELECT * FROM news ORDER BY ID";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$headline = $row['headline'];
$username1 = $row['username'];
$mainnews = $row['mainnews'];
$date = $row['date'];
$i = 1;
while ($row = mysql_fetch_assoc($result))
{
if ($i % 2 == 0) {
$bg = "#e1e1e1";
else
$bg = "#eeeeee";
}
$i ++
echo "<tr><td bgcolor=".$bg.">";
echo "<font face='verdana' size=1>";
echo "<b>.:$headline:.</b> Posted By: $username1 - <i>$date</i><br><hr color='black'>";
echo "$mainnews<p>";
echo "<a href='changes/edit4.php'>Edit Post</a> ";
echo "</td></tr>";
}
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
probably has something to do with at least 2 fetches happening without reseting the sql pointers..
look into mysql_data_seek()
look into mysql_data_seek()
Hey great thanks a lot guys for all of your help. In the end up I managed to get it using:
$sql = "SELECT * FROM news ORDER BY ID";
$result = mysql_query($sql) or die(mysql_error());
$i = 1;
while ($row = mysql_fetch_assoc($result))
{
$headline = $row['headline'];
$username1 = $row['username'];
$mainnews = $row['mainnews'];
$comments = $row['comments'];
$date = $row['date'];
if ($i % 2 == 0)
$bg = "#e1e1e1";
else
$bg = "#eeeeee";
$i ++;
echo "<tr><td bgcolor=".$bg.">";
echo "<font face='verdana' size=1>";
echo "<b>.:$headline:.</b> Posted By: $username1 - <i>$date</i><br><hr color='black'>";
echo "$mainnews<p>";
echo "<a href='changes/edit4.php'>Edit Post</a> ";
echo "</td></tr>";
}
It must have been 2 fetches at the same time. Thanks!
$sql = "SELECT * FROM news ORDER BY ID";
$result = mysql_query($sql) or die(mysql_error());
$i = 1;
while ($row = mysql_fetch_assoc($result))
{
$headline = $row['headline'];
$username1 = $row['username'];
$mainnews = $row['mainnews'];
$comments = $row['comments'];
$date = $row['date'];
if ($i % 2 == 0)
$bg = "#e1e1e1";
else
$bg = "#eeeeee";
$i ++;
echo "<tr><td bgcolor=".$bg.">";
echo "<font face='verdana' size=1>";
echo "<b>.:$headline:.</b> Posted By: $username1 - <i>$date</i><br><hr color='black'>";
echo "$mainnews<p>";
echo "<a href='changes/edit4.php'>Edit Post</a> ";
echo "</td></tr>";
}
It must have been 2 fetches at the same time. Thanks!