Page 1 of 1

[SOLVED] How to show evry other row in diferent color

Posted: Tue Jul 06, 2004 1:49 am
by ddragas
How to show evry other row in diferent color

colors should be:

#CCCC99 and #CCCCCC

Code: Select all

<?php

include("con_db.php");

$query_count2 = mysql_query("select city, mjesto, count(*) as 'broj_iznajmljivaca' 
from apartmani
where Zupanija = '$zupanija_smjestaja' and vrsta_smjestaja='$vrsta'  and kategorija='$kategorija'
group by city, mjesto
order by city ") or
die (mysql_error());


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			while ($result_row2 = mysql_fetch_assoc($query_count2)){
			$totalrows2 = $result_row2['broj_iznajmljivaca']; 
			$grad = $result_row2["city"];
			$mjesto =  $result_row2["mjesto"];
			
		
			echo "<table border = 1 table width="100%">"; 
			if($vrsta=="apartman"){
			echo "<td width="40%"align="left">" . $font .  $grad  . " (" . $mjesto. ")" . "</td><td width="20%"align="center">" . $font . '<a href="result_app.php?grad='.urlencode($grad).'&mjesto=' . urlencode($mjesto) .'&vrsta=' . urlencode($vrsta) .'">' .  $totalrows2 .  '</a>' . "</td>";}
			if($vrsta=="soba"){
			echo "<td width="40%"align="left">" . $font .  $grad  . " (" . $mjesto. ")" . "</td><td width="20%"align="center">" . $font . '<a href="result_soba.php?grad='.urlencode($grad).'&mjesto=' . urlencode($mjesto) .'&vrsta=' . urlencode($vrsta) .'">' .  $totalrows2 .  '</a>' . "</td>";}
			if($vrsta=="agroturizam"){
			echo "<td width="40%"align="left">" . $font .  $grad  . " (" . $mjesto. ")" . "</td><td width="20%"align="center">" . $font . '<a href="result_agroturizam.php?grad='.urlencode($grad).'&mjesto=' . urlencode($mjesto) .'&vrsta=' . urlencode($vrsta) .'">' .  $totalrows2 .  '</a>' . "</td>";}
			echo "</table>"; 
			}
mysql_free_result($query_count2);
mysql_close($conn); 


<?php

?>

Posted: Tue Jul 06, 2004 2:29 am
by feyd
something like

Code: Select all

<?php

include("con_db.php");

$query_count2 = mysql_query("select city, mjesto, count(*) as 'broj_iznajmljivaca' 
from apartmani
where Zupanija = '$zupanija_smjestaja' and vrsta_smjestaja='$vrsta'  and kategorija='$kategorija'
group by city, mjesto
order by city ") or
die (mysql_error());


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			$color = '#CCCC99';
			while ($result_row2 = mysql_fetch_assoc($query_count2)){
			$totalrows2 = $result_row2['broj_iznajmljivaca']; 
			$grad = $result_row2["city"];
			$mjesto =  $result_row2["mjesto"];
			
		
			echo "<table border = 1 table width="100%" bgcolor="$color">"; 
			if($vrsta=="apartman"){
			echo "<td width="40%"align="left">" . $font .  $grad  . " (" . $mjesto. ")" . "</td><td width="20%"align="center">" . $font . '<a href="result_app.php?grad='.urlencode($grad).'&mjesto=' . urlencode($mjesto) .'&vrsta=' . urlencode($vrsta) .'">' .  $totalrows2 .  '</a>' . "</td>";}
			if($vrsta=="soba"){
			echo "<td width="40%"align="left">" . $font .  $grad  . " (" . $mjesto. ")" . "</td><td width="20%"align="center">" . $font . '<a href="result_soba.php?grad='.urlencode($grad).'&mjesto=' . urlencode($mjesto) .'&vrsta=' . urlencode($vrsta) .'">' .  $totalrows2 .  '</a>' . "</td>";}
			if($vrsta=="agroturizam"){
			echo "<td width="40%"align="left">" . $font .  $grad  . " (" . $mjesto. ")" . "</td><td width="20%"align="center">" . $font . '<a href="result_agroturizam.php?grad='.urlencode($grad).'&mjesto=' . urlencode($mjesto) .'&vrsta=' . urlencode($vrsta) .'">' .  $totalrows2 .  '</a>' . "</td>";}
			echo "</table>"; 
			$color = ($color === '#CCCC99' ? '#CCCCCC' : '#CCCC99');
			}
mysql_free_result($query_count2);
mysql_close($conn); 


?>
Additionally, you aren't putting table rows in there. In fact, you're writing out several individual tables..

Posted: Tue Jul 06, 2004 2:52 am
by ddragas
Thank you

Posted: Tue Jul 06, 2004 7:10 am
by ddragas
you're rigt

I'm making two individual tables. What am I doing wrong?

I want to make one table, and make rows in that table


Here is complete code

Code: Select all

<?php

include("con_db.php");

$query_count2 = mysql_query("select city, mjesto, count(*) as 'broj_iznajmljivaca' 
from apartmani
where Zupanija = '$zupanija_smjestaja' and vrsta_smjestaja='$vrsta'  and kategorija='$kategorija'
group by city, mjesto
order by city ") or
die (mysql_error());


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			$color = '#CCCC99'; 
			while ($result_row2 = mysql_fetch_assoc($query_count2)){
			$totalrows2 = $result_row2['broj_iznajmljivaca']; 
			$grad = $result_row2["city"];
			$mjesto =  $result_row2["mjesto"];
			
			$color = ($color === '#CCCC99' ? '#CCCCCC' : '#CCCC99');
			echo "<table border = -1 table width="100%">"; 
			if($vrsta=="apartman"){
			echo "<td width="40%"align="left" bgcolor= "  . $color  . ">" . $font .  $grad  . " (" . $mjesto. ")" . "</td><td width="20%"align="center" bgcolor= "  . $color  . ">" . $font . '<a href="result_app.php?grad='.urlencode($grad).'&mjesto=' . urlencode($mjesto) .'&vrsta=' . urlencode($vrsta) .'">' .  $totalrows2 .  '</a>' . "</td></tr>";}
			echo "</table>"; 
	//		$color = ($color === '#CCCC99' ? '#CCCCCC' : '#CCCC99');
			}
mysql_free_result($query_count2);
mysql_close($conn); 

?>

<?php

?>

Posted: Tue Jul 06, 2004 9:55 am
by feyd
move the table echo outside the while loop, add an echo for <tr></tr> around the echo(s) still inside the while loop.