Jump to content


Two different background colours after readout


  • Please log in to reply
13 replies to this topic

#1 Guest_SwordKing_*

Guest_SwordKing_*
  • Guests

Posted 25 July 2006 - 01:11 AM

hey all.

Imagine an index like,

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


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

That can't be so difficult or ?

Thats the basic MySQL Code :

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 ;


Can you help me ?


#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 25 July 2006 - 02:07 AM

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>';
}


#3 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 25 July 2006 - 03:29 AM

$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++;
}
or
$i=0;
while ($row = mysql_fetch_query($result, MYSQL_ASSOC)) {
  echo '<tr><td class="colour'.($bg[$i%2]+1).';">'.$row['name'].'</td></tr>';
  $i++;
}

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#4 Guest_SwordKing_*

Guest_SwordKing_*
  • Guests

Posted 25 July 2006 - 03:22 PM

hm it does not work this way :

<?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>

error message :

Fatal error: Call to undefined function: mysql_fetch_query() in /srv/www/htdocs/web45/html/LK/show/team22.php on line 13



#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 July 2006 - 03:24 PM

This:
while ($sq = mysql_fetch_query($result, MYSQL_ASSOC)) {
is supposed to be this:
while ($sq = mysql_fetch_assoc($result)) {


#6 Guest_SwordKing_*

Guest_SwordKing_*
  • Guests

Posted 25 July 2006 - 03:27 PM

You mean that (t instead of y in "resuly" :

<?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 } ?>

gives me a parse error here :

while ($sq = mysql_fetch_assoc($result) {



#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 July 2006 - 03:39 PM

Of course it does. Look at it! Should be...

while ($sq = mysql_fetch_assoc($result)) {


#8 Guest_SwordKing_*

Guest_SwordKing_*
  • Guests

Posted 25 July 2006 - 03:57 PM

Of course it does. Look at it! Should be...

while ($sq = mysql_fetch_assoc($result)) {


gives me a different kind of error :/

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource


Is $result even defined ?

#9 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 25 July 2006 - 04:45 PM

replace $result with $data
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#10 Guest_SwordKing_*

Guest_SwordKing_*
  • Guests

Posted 25 July 2006 - 04:56 PM

The readout works without errors, but he is not able to replace the variables. Now it looks that way :

<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>.....


here is the code once again (edited) :

<?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 } ?>



#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 July 2006 - 05:04 PM

It is becuase of the single quotes, this should work:
<?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 } ?>
EDIT: Didnt copy correctly

#12 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 25 July 2006 - 05:06 PM

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
<?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>

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#13 Guest_SwordKing_*

Guest_SwordKing_*
  • Guests

Posted 25 July 2006 - 05:22 PM

ou yeah. That runs !  Here is the perfect code whitout any mistakes :

<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>

Thanks to all, who tried to help me :)

See you !

#14 Guest_SwordKing_*

Guest_SwordKing_*
  • Guests

Posted 25 July 2006 - 09:55 PM

My new question to this $i comes with new topic !




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users