Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest SwordKing

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 ?

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
This:
[code]while ($sq = mysql_fetch_query($result, MYSQL_ASSOC)) {[/code]
is supposed to be this:
[code]while ($sq = mysql_fetch_assoc($result)) {[/code]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Of course it does. Look at it! Should be...

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

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 !

Share this post


Link to post
Share on other sites
Guest SwordKing
My new question to this [b]$i[/b] comes with new topic !

Share this post


Link to post
Share on other sites

×

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.