Guest SwordKing Posted July 25, 2006 Share Posted July 25, 2006 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/ Share on other sites More sharing options...
hitman6003 Posted July 25, 2006 Share Posted July 25, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63210 Share on other sites More sharing options...
ryanlwh Posted July 25, 2006 Share Posted July 25, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63231 Share on other sites More sharing options...
Guest SwordKing Posted July 25, 2006 Share Posted July 25, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63429 Share on other sites More sharing options...
wildteen88 Posted July 25, 2006 Share Posted July 25, 2006 This:[code]while ($sq = mysql_fetch_query($result, MYSQL_ASSOC)) {[/code]is supposed to be this:[code]while ($sq = mysql_fetch_assoc($result)) {[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63431 Share on other sites More sharing options...
Guest SwordKing Posted July 25, 2006 Share Posted July 25, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63435 Share on other sites More sharing options...
trq Posted July 25, 2006 Share Posted July 25, 2006 Of course it does. Look at it! Should be...[code=php:0]while ($sq = mysql_fetch_assoc($result)) {[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63445 Share on other sites More sharing options...
Guest SwordKing Posted July 25, 2006 Share Posted July 25, 2006 [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 ? Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63453 Share on other sites More sharing options...
ryanlwh Posted July 25, 2006 Share Posted July 25, 2006 replace $result with $data Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63481 Share on other sites More sharing options...
Guest SwordKing Posted July 25, 2006 Share Posted July 25, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63488 Share on other sites More sharing options...
wildteen88 Posted July 25, 2006 Share Posted July 25, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63499 Share on other sites More sharing options...
ryanlwh Posted July 25, 2006 Share Posted July 25, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63501 Share on other sites More sharing options...
Guest SwordKing Posted July 25, 2006 Share Posted July 25, 2006 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63513 Share on other sites More sharing options...
Guest SwordKing Posted July 25, 2006 Share Posted July 25, 2006 My new question to this [b]$i[/b] comes with new topic ! Quote Link to comment https://forums.phpfreaks.com/topic/15552-two-different-background-colours-after-readout/#findComment-63666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.