Jump to content

Two different background colours after readout


Recommended Posts

Guest SwordKing
hey all.

Imagine an index like,

[quote]
<table>
<tr><td class="colour1">bla</td>
</tr>
<td class="colour2">bla2</td>
</tr>
</table>
[/quote]

All I want is, that my code shows rotational "colour1" and "colour2".

That can't be so difficult or ?

Thats the basic MySQL Code :

[quote]
CREATE TABLE `squads` (
  `id` int(5) unsigned NOT NULL auto_increment,
  `name` varchar(80) NOT NULL default '',
  `short` varchar(10) NOT NULL default '',
  `game` varchar(80) NOT NULL default '',
  `showme` varchar(9) NOT NULL default '',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`),
  KEY `id_2` (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
[/quote]

Can you help me ?
[code]
while ($row = mysql_fetch_query($result, MYSQL_ASSOC)) {
  if ($bg == '#CCCCCC') {
    $bg = '#EEEEEE';
  } else {
    $bg = '#CCCCCC';
  }
  echo '<tr><td style="background-color:' . $bg . ';">' . $row['name'] . '</td></tr>';
}[/code]
[code]$bg = array('#CCCCCC','#EEEEEE');
$i=0;
while ($row = mysql_fetch_query($result, MYSQL_ASSOC)) {
  echo '<tr><td style="background-color:'.$bg[$i%2].';">'.$row['name'].'</td></tr>';
  $i++;
}[/code]
or
[code]
$i=0;
while ($row = mysql_fetch_query($result, MYSQL_ASSOC)) {
  echo '<tr><td class="colour'.($bg[$i%2]+1).';">'.$row['name'].'</td></tr>';
  $i++;
}[/code]
Guest SwordKing
hm it does not work this way :

[code]
<?php $sql="SELECT * FROM squads WHERE showme='all' OR showme='teams' ORDER BY id";
$data=mysql_query($sql, $db);
while ($sq = mysql_fetch_object ($data)) { ?>

<?php $bg = array('#CCCCCC','#EEEEEE');
$i=0;
while ($sq = mysql_fetch_query($result, MYSQL_ASSOC)) {
  echo '<tr><td style="background-color:'.$bg[$i%2].';"><div align=\"left\"><a href=\"index.php?show=sq$sq->short\"><img src=\"symbols/games/$sq->game\" alt=\"\" /> $sq->name</a></div></td></tr>';
  $i++;
} ?>

<?php } ?>

</table>[/code]

error message :

[quote]
Fatal error: Call to undefined function: mysql_fetch_query() in /srv/www/htdocs/web45/html/LK/show/team22.php on line 13[/quote]
Guest SwordKing
You mean that (t instead of y in "resuly" :

[code]
<?php $bg = array('#CCCCCC','#EEEEEE');
$i=0;
while ($sq = mysql_fetch_assoc($result) {
  echo '<tr><td style="background-color:'.$bg[$i%2].';"><div align=\"left\"><a href=\"index.php?show=sq$sq->short\"><img src=\"symbols/games/$sq->game\" alt=\"\" /> $sq->name</a></div></td></tr>';
  $i++;
} ?>

<?php } ?>[/code]

gives me a parse error here :

[quote]while ($sq = mysql_fetch_assoc($result) {[/quote]
Guest SwordKing
[quote author=thorpe link=topic=101753.msg403232#msg403232 date=1153841988]
Of course it does. Look at it! Should be...

[code=php:0]
while ($sq = mysql_fetch_assoc($result)) {
[/code]
[/quote]

gives me a different kind of error :/
[quote]Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource[/quote]

Is $result even defined ?
Guest SwordKing
The readout works without errors, but he is not able to replace the variables. Now it looks that way :

[quote]<tr><td class="team22" style="background-color:#CCCCCC;"><a href="index.php?show=sq$sq->short"><img src="symbols/games/$sq->game"> $sq->name</a></td></tr><tr><td class="team22" style="background-color:#EEEEEE;"><a href="index.php?show=sq$sq->short"><img src="symbols/games/$sq->game"> $sq->name</a></td></tr>.....[/quote]

here is the code once again (edited) :

[code]<?php $bg = array('#CCCCCC','#EEEEEE');
$i=0;
while ($sq = mysql_fetch_assoc($data)) {
  print '<tr><td class="team22" style="background-color:'.$bg[$i%2].';"><a href="index.php?show=sq$sq->short"><img src="symbols/games/$sq->game"> $sq->name</a></td></tr>';
  $i++;
} ?>

<?php } ?>[/code]

It is becuase of the single quotes, this should work:
[code]<?php $bg = array('#CCCCCC','#EEEEEE');
$i=0;
while ($sq = mysql_fetch_assoc($data)) {
  print '<tr><td class="team22" style="background-color:'.$bg[$i%2].';"><a href="index.php?show=sq'.$sq->short.'"><img src="symbols/games/'.$sq->game.'">'.$sq->name.'</a></td></tr>';
  $i++;
} ?>

<?php } ?>[/code]
EDIT: Didnt copy correctly
i assume you don't actually want to put mysql_fetch_assoc within mysql_fetch_object???
here's what i suppose should work for you
[code]<?php $sql="SELECT * FROM squads WHERE showme='all' OR showme='teams' ORDER BY id";
$data=mysql_query($sql, $db);
$bg = array('#CCCCCC','#EEEEEE');
$i=0;

while ($sq = mysql_fetch_object ($data)) {
  echo '<tr><td style="background-color:'.$bg[$i%2].';"><div align=\"left\"><a href=\"index.php?show=sq'.$sq->short.'\"><img src=\"symbols/games/'.$sq->game.'\" alt=\"\" /> '.$sq->name.'</a></div></td></tr>';
  $i++;
} ?>

</table>
[/code]
Guest SwordKing
ou yeah. That runs !  Here is the perfect code whitout any mistakes :

[code]<table border="0" cellpadding="0" cellspacing="0" class="forum" style="<?php echo "$contbreit"; ?>">

<?php $sql="SELECT * FROM squads WHERE showme='all' OR showme='teams' ORDER BY id";
$data=mysql_query($sql, $db);
$bg = array('#CCCCCC','#EEEEEE');
$i=0;

while ($sq = mysql_fetch_object ($data)) {
  echo '<tr><td class="team22" style="background-color:'.$bg[$i%2].';"><a href="index.php?show=sq'.$sq->short.'"><img src="symbols/games/'.$sq->game.'" /> '.$sq->name.'</a></div></td></tr>';
  $i++;
} ?>

</table>[/code]

Thanks to all, who tried to help me :)

See you !
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.